AsynchronousLock: implement _poll() and test
authorZac Medico <zmedico@gentoo.org>
Tue, 17 May 2011 21:25:47 +0000 (14:25 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 26 May 2011 03:05:49 +0000 (20:05 -0700)
pym/_emerge/AsynchronousLock.py
pym/_emerge/AsynchronousTask.py
pym/portage/tests/locks/test_asynchronous_lock.py

index 1135df744a6c3d3b5f92914428a8a04319e7a1fd..86b102b8bda1aef1716d4631c5ce79f660aa2079 100644 (file)
@@ -73,6 +73,11 @@ class AsynchronousLock(AsynchronousTask):
                if self._imp is not None:
                        self._imp.cancel()
 
+       def _poll(self):
+               if self._imp is not None:
+                       return self._imp.poll()
+               return self.returncode
+
        def _wait(self):
                if self.returncode is not None:
                        return self.returncode
@@ -232,6 +237,11 @@ class _LockProcess(AbstractPollTask):
                if self._proc is not None:
                        self._proc.cancel()
 
+       def _poll(self):
+               if self._proc is not None:
+                       return self._proc.poll()
+               return self.returncode
+
        def _wait(self):
                if self.returncode is not None:
                        return self.returncode
index de0080042a9f19bd424b3886267807e3e082d308..bd722912bab11f7c231139b4e6c8c14a1daeebe8 100644 (file)
@@ -30,6 +30,8 @@ class AsynchronousTask(SlotObject):
 
        def poll(self):
                self._wait_hook()
+               if self.returncode is not None:
+                       return self.returncode
                return self._poll()
 
        def _poll(self):
index d592f4b22d0ad0a14aaaadd6e2150cdeccdb0689..50b9c93a5c10981d12441e43669b25c6a8ad553e 100644 (file)
@@ -56,6 +56,7 @@ class AsynchronousLockTestCase(TestCase):
                                _force_async=True, _force_process=True)
                        lock2.start()
                        # lock2 should we waiting for lock1 to release
+                       self.assertEqual(lock2.poll(), None)
                        self.assertEqual(lock2.returncode, None)
 
                        lock1.unlock()
@@ -78,6 +79,7 @@ class AsynchronousLockTestCase(TestCase):
                                _force_async=True, _force_process=True)
                        lock2.start()
                        # lock2 should we waiting for lock1 to release
+                       self.assertEqual(lock2.poll(), None)
                        self.assertEqual(lock2.returncode, None)
 
                        # Cancel lock2 and then check wait() and returncode results.