From 1650ac2944b7cbd5a462d2ce39993e2f202807c4 Mon Sep 17 00:00:00 2001
From: Zac Medico <zmedico@gentoo.org>
Date: Tue, 17 May 2011 14:25:47 -0700
Subject: [PATCH] AsynchronousLock: implement _poll() and test

---
 pym/_emerge/AsynchronousLock.py                   | 10 ++++++++++
 pym/_emerge/AsynchronousTask.py                   |  2 ++
 pym/portage/tests/locks/test_asynchronous_lock.py |  2 ++
 3 files changed, 14 insertions(+)

diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py
index 1135df744..86b102b8b 100644
--- a/pym/_emerge/AsynchronousLock.py
+++ b/pym/_emerge/AsynchronousLock.py
@@ -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
diff --git a/pym/_emerge/AsynchronousTask.py b/pym/_emerge/AsynchronousTask.py
index 2b654ec00..cac1d5594 100644
--- a/pym/_emerge/AsynchronousTask.py
+++ b/pym/_emerge/AsynchronousTask.py
@@ -32,6 +32,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):
diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index d592f4b22..50b9c93a5 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -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.
-- 
2.26.2