aboutsummaryrefslogtreecommitdiffstats
path: root/test_archivemail.py
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2009-05-22 19:40:07 +0200
committerNikolaus Schulz <microschulz@web.de>2010-07-19 01:13:25 +0200
commit11103e2de2836f780adf17175f4fff189e1ebcaf (patch)
tree224140c7cbbf8d0d9b9624aa5d4fff2033f92382 /test_archivemail.py
parentd706409c595a5994371d2b238b2a5e77be171f13 (diff)
downloadarchivemail-11103e2de2836f780adf17175f4fff189e1ebcaf.tar.gz
archivemail-11103e2de2836f780adf17175f4fff189e1ebcaf.tar.bz2
archivemail-11103e2de2836f780adf17175f4fff189e1ebcaf.zip
mbox locking: combine locking functions into one and swap lock order
We used to create a dotlock file first and then lock with fcntl; swap that order, since locking first with fcntl seems to be more common. This patch also adds general mbox lock/unlock methods, which call the dotlock and fcntl-lock methods, and moves the retry logic there. When the dotlock and fcntl methods fail to acquire a lock, they now raise a custom exception "LockUnavailable", which gets caught in the general lock() method. That way, if we succeed to acquire one lock but fail to acquire the other, we can release our locks at the upper level and retry.
Diffstat (limited to 'test_archivemail.py')
-rwxr-xr-xtest_archivemail.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/test_archivemail.py b/test_archivemail.py
index a2d4767..55c294f 100755
--- a/test_archivemail.py
+++ b/test_archivemail.py
@@ -115,9 +115,9 @@ class TestMboxDotlock(TestCaseInTempdir):
def testDotlock(self):
"""dotlock_lock/unlock should create/delete a lockfile"""
lock = self.mbox_name + ".lock"
- self.mbox.dotlock_lock()
+ self.mbox._dotlock_lock()
assert(os.path.isfile(lock))
- self.mbox.dotlock_unlock()
+ self.mbox._dotlock_unlock()
assert(not os.path.isfile(lock))
class TestMboxPosixLock(TestCaseInTempdir):
@@ -138,9 +138,9 @@ class TestMboxPosixLock(TestCaseInTempdir):
pid = os.fork()
if pid == 0:
# In the child, lock the mailbox.
- self.mbox.posix_lock()
+ self.mbox._posix_lock()
time.sleep(2)
- self.mbox.posix_unlock()
+ self.mbox._posix_unlock()
os._exit(0)
# In the parent, sleep a bit to give the child time to acquire