##// END OF EJS Templates
test-lock.py: fix testing for forks...
Siddharth Agarwal -
r26386:146cccdb default
parent child Browse files
Show More
@@ -1,8 +1,10 b''
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 (
@@ -12,6 +14,12 b' from mercurial import ('
12
14
13 testlockname = 'testlock'
15 testlockname = 'testlock'
14
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
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
@@ -128,16 +136,16 b' class testlock(unittest.TestCase):'
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)
General Comments 0
You need to be logged in to leave comments. Login now