OLD | NEW |
| (Empty) |
1 # Copyright (c) 2005 Divmod, Inc. | |
2 # See LICENSE for details. | |
3 | |
4 from twisted.trial import unittest | |
5 from twisted.python import lockfile | |
6 | |
7 class LockingTestCase(unittest.TestCase): | |
8 def testBasics(self): | |
9 lockf = self.mktemp() | |
10 lock = lockfile.FilesystemLock(lockf) | |
11 self.failUnless(lock.lock()) | |
12 self.failUnless(lock.clean) | |
13 lock.unlock() | |
14 self.failUnless(lock.lock()) | |
15 self.failUnless(lock.clean) | |
16 lock.unlock() | |
17 | |
18 | |
19 def testProtection(self): | |
20 lockf = self.mktemp() | |
21 lock = lockfile.FilesystemLock(lockf) | |
22 self.failUnless(lock.lock()) | |
23 self.failUnless(lock.clean) | |
24 self.failIf(lock.lock()) | |
25 lock.unlock() | |
26 | |
27 | |
28 def testBigLoop(self): | |
29 lockf = self.mktemp() | |
30 lock = lockfile.FilesystemLock(lockf) | |
31 self.failUnless(lock.lock()) | |
32 for i in xrange(500): | |
33 self.failIf(lock.lock()) | |
34 lock.unlock() | |
35 | |
36 | |
37 def testIsLocked(self): | |
38 lockf = self.mktemp() | |
39 self.failIf(lockfile.isLocked(lockf)) | |
40 lock = lockfile.FilesystemLock(lockf) | |
41 self.failUnless(lock.lock()) | |
42 self.failUnless(lockfile.isLocked(lockf)) | |
43 lock.unlock() | |
44 self.failIf(lockfile.isLocked(lockf)) | |
45 | |
46 # A multiprocess test would be good here, for the sake of | |
47 # completeness. However, it is fairly safe to rely on the | |
48 # filesystem to provide the semantics we require. | |
49 | |
OLD | NEW |