Mercurial > hg-stable
comparison tests/test-lock.py @ 26382:b673e89affc9
test-lock.py: move temp dir generation to testcase
In upcoming patches we'll want to create multiple test state objects with a
common test directory.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Thu, 24 Sep 2015 19:52:34 -0700 |
parents | 94dc10834b79 |
children | ad6e56d01c30 |
comparison
equal
deleted
inserted
replaced
26381:94dc10834b79 | 26382:b673e89affc9 |
---|---|
11 ) | 11 ) |
12 | 12 |
13 testlockname = 'testlock' | 13 testlockname = 'testlock' |
14 | 14 |
15 class teststate(object): | 15 class teststate(object): |
16 def __init__(self, testcase): | 16 def __init__(self, testcase, dir): |
17 self._testcase = testcase | 17 self._testcase = testcase |
18 self._acquirecalled = False | 18 self._acquirecalled = False |
19 self._releasecalled = False | 19 self._releasecalled = False |
20 self._postreleasecalled = False | 20 self._postreleasecalled = False |
21 d = tempfile.mkdtemp(dir=os.getcwd()) | 21 self.vfs = scmutil.vfs(dir, audit=False) |
22 self.vfs = scmutil.vfs(d, audit=False) | |
23 | 22 |
24 def makelock(self, *args, **kwargs): | 23 def makelock(self, *args, **kwargs): |
25 l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn, | 24 l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn, |
26 acquirefn=self.acquirefn, *args, **kwargs) | 25 acquirefn=self.acquirefn, *args, **kwargs) |
27 l.postrelease.append(self.postreleasefn) | 26 l.postrelease.append(self.postreleasefn) |
84 else: | 83 else: |
85 return 'not exist' | 84 return 'not exist' |
86 | 85 |
87 class testlock(unittest.TestCase): | 86 class testlock(unittest.TestCase): |
88 def testlock(self): | 87 def testlock(self): |
89 state = teststate(self) | 88 state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) |
90 lock = state.makelock() | 89 lock = state.makelock() |
91 state.assertacquirecalled(True) | 90 state.assertacquirecalled(True) |
92 lock.release() | 91 lock.release() |
93 state.assertreleasecalled(True) | 92 state.assertreleasecalled(True) |
94 state.assertpostreleasecalled(True) | 93 state.assertpostreleasecalled(True) |
95 state.assertlockexists(False) | 94 state.assertlockexists(False) |
96 | 95 |
97 def testrecursivelock(self): | 96 def testrecursivelock(self): |
98 state = teststate(self) | 97 state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) |
99 lock = state.makelock() | 98 lock = state.makelock() |
100 state.assertacquirecalled(True) | 99 state.assertacquirecalled(True) |
101 | 100 |
102 state.resetacquirefn() | 101 state.resetacquirefn() |
103 lock.lock() | 102 lock.lock() |
113 state.assertreleasecalled(True) | 112 state.assertreleasecalled(True) |
114 state.assertpostreleasecalled(True) | 113 state.assertpostreleasecalled(True) |
115 state.assertlockexists(False) | 114 state.assertlockexists(False) |
116 | 115 |
117 def testlockfork(self): | 116 def testlockfork(self): |
118 state = teststate(self) | 117 state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) |
119 lock = state.makelock() | 118 lock = state.makelock() |
120 state.assertacquirecalled(True) | 119 state.assertacquirecalled(True) |
121 lock.lock() | 120 lock.lock() |
122 # fake a fork | 121 # fake a fork |
123 lock.pid += 1 | 122 lock.pid += 1 |