test_asynchronous_lock: test waiting
authorZac Medico <zmedico@gentoo.org>
Tue, 17 May 2011 20:56:15 +0000 (13:56 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 26 May 2011 03:05:23 +0000 (20:05 -0700)
pym/portage/tests/locks/test_asynchronous_lock.py

index 7e9fdfec9f432fcb3d4fc8d5f48a9d2a0dbb003f..e72adf684693ec7eb45c3116fc95f65f5b2ed2f3 100644 (file)
@@ -37,3 +37,28 @@ class AsynchronousLockTestCase(TestCase):
 
                finally:
                        shutil.rmtree(tempdir)
+
+       def testAsynchronousLockWait(self):
+               scheduler = PollScheduler().sched_iface
+               tempdir = tempfile.mkdtemp()
+               try:
+                       path = os.path.join(tempdir, 'lock_me')
+                       lock1 = AsynchronousLock(path=path, scheduler=scheduler)
+                       lock1.start()
+                       self.assertEqual(lock1.wait(), os.EX_OK)
+
+                       # lock2 requires _force_async=True since the portage.locks
+                       # module is not designed to work as intended here if the
+                       # same process tries to lock the same file more than
+                       # one time concurrently.
+                       lock2 = AsynchronousLock(path=path, scheduler=scheduler,
+                               _force_async=True, _force_process=True)
+                       lock2.start()
+                       # lock2 should we waiting for lock1 to release
+                       self.assertEqual(lock2.returncode, None)
+
+                       lock1.unlock()
+                       self.assertEqual(lock2.wait(), os.EX_OK)
+                       lock2.unlock()
+               finally:
+                       shutil.rmtree(tempdir)