equal
deleted
inserted
replaced
1 from __future__ import absolute_import |
1 from __future__ import absolute_import |
2 |
2 |
|
3 import copy |
3 import os |
4 import os |
4 import silenttestrunner |
5 import silenttestrunner |
5 import tempfile |
6 import tempfile |
|
7 import types |
6 import unittest |
8 import unittest |
7 |
9 |
8 from mercurial import ( |
10 from mercurial import ( |
9 lock, |
11 lock, |
10 scmutil, |
12 scmutil, |
11 ) |
13 ) |
12 |
14 |
13 testlockname = 'testlock' |
15 testlockname = 'testlock' |
|
16 |
|
17 # work around http://bugs.python.org/issue1515 |
|
18 if types.MethodType not in copy._deepcopy_dispatch: |
|
19 def _deepcopy_method(x, memo): |
|
20 return type(x)(x.im_func, copy.deepcopy(x.im_self, memo), x.im_class) |
|
21 copy._deepcopy_dispatch[types.MethodType] = _deepcopy_method |
14 |
22 |
15 class lockwrapper(lock.lock): |
23 class lockwrapper(lock.lock): |
16 def __init__(self, pidoffset, *args, **kwargs): |
24 def __init__(self, pidoffset, *args, **kwargs): |
17 # lock.lock.__init__() calls lock(), so the pidoffset assignment needs |
25 # lock.lock.__init__() calls lock(), so the pidoffset assignment needs |
18 # to be earlier |
26 # to be earlier |
126 |
134 |
127 def testlockfork(self): |
135 def testlockfork(self): |
128 state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) |
136 state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) |
129 lock = state.makelock() |
137 lock = state.makelock() |
130 state.assertacquirecalled(True) |
138 state.assertacquirecalled(True) |
131 lock.lock() |
139 |
132 # fake a fork |
140 # fake a fork |
133 lock.pid += 1 |
141 forklock = copy.deepcopy(lock) |
134 lock.release() |
142 forklock._pidoffset = 1 |
|
143 forklock.release() |
135 state.assertreleasecalled(False) |
144 state.assertreleasecalled(False) |
136 state.assertpostreleasecalled(False) |
145 state.assertpostreleasecalled(False) |
137 state.assertlockexists(True) |
146 state.assertlockexists(True) |
138 |
147 |
139 # release the actual lock |
148 # release the actual lock |
140 lock.pid -= 1 |
|
141 lock.release() |
149 lock.release() |
142 state.assertreleasecalled(True) |
150 state.assertreleasecalled(True) |
143 state.assertpostreleasecalled(True) |
151 state.assertpostreleasecalled(True) |
144 state.assertlockexists(False) |
152 state.assertlockexists(False) |
145 |
153 |