summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-06-26 13:23:10 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-06-26 13:23:10 (GMT)
commit9afbacef2758223ba3190b459fcf794c7cc855e5 (patch)
tree800bb3c492b6349196059f0472d06ce179808b7b /Lib/test
parent557325930ce81804a1dd9c6f0e3babb8673afdd5 (diff)
downloadcpython-9afbacef2758223ba3190b459fcf794c7cc855e5.zip
cpython-9afbacef2758223ba3190b459fcf794c7cc855e5.tar.gz
cpython-9afbacef2758223ba3190b459fcf794c7cc855e5.tar.bz2
Add a test for a conflicting lock.
On slow machines, maybe the time intervals (2 sec, 0.5 sec) will be too tight. I'll see how the buildbots like it.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_mailbox.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 914a20c..ad25404 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -720,6 +720,28 @@ class _TestMboxMMDF(TestMailbox):
self.assert_(contents == open(self._path, 'rb').read())
self._box = self._factory(self._path)
+ def test_lock_conflict(self):
+ # Fork off a subprocess that will lock the file for 2 seconds,
+ # unlock it, and then exit.
+ pid = os.fork()
+ if pid == 0:
+ # In the child, lock the mailbox.
+ self._box.lock()
+ time.sleep(2)
+ self._box.unlock()
+ os._exit(0)
+
+ # In the parent, sleep a bit to give the child time to acquire
+ # the lock.
+ time.sleep(0.5)
+ self.assertRaises(mailbox.ExternalClashError,
+ self._box.lock)
+
+ # Wait for child to exit. Locking should now succeed.
+ pid, status = os.wait()
+ self._box.lock()
+ self._box.unlock()
+
class TestMbox(_TestMboxMMDF):