[Python-checkins] r47101 - python/trunk/Lib/test/test_mailbox.py

andrew.kuchling python-checkins at python.org
Mon Jun 26 15:23:11 CEST 2006


Author: andrew.kuchling
Date: Mon Jun 26 15:23:10 2006
New Revision: 47101
Modified:
 python/trunk/Lib/test/test_mailbox.py
Log:
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.
Modified: python/trunk/Lib/test/test_mailbox.py
==============================================================================
--- python/trunk/Lib/test/test_mailbox.py	(original)
+++ python/trunk/Lib/test/test_mailbox.py	Mon Jun 26 15:23:10 2006
@@ -720,6 +720,28 @@
 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):
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /