# HG changeset patch # User Siddharth Agarwal # Date 2015-09-25 05:00:51 # Node ID 146cccdb282b60f1efe43e3bf72f8593bbbcdfe1 # Parent fb1a424e8bffe3bdb9eabaf24379414f01fb43d4 test-lock.py: fix testing for forks The earlier test worked only because the held count went up to 2, so the first release brought it down to 1. Making a copy of the lock fixes that issue. diff --git a/tests/test-lock.py b/tests/test-lock.py --- a/tests/test-lock.py +++ b/tests/test-lock.py @@ -1,8 +1,10 @@ from __future__ import absolute_import +import copy import os import silenttestrunner import tempfile +import types import unittest from mercurial import ( @@ -12,6 +14,12 @@ from mercurial import ( testlockname = 'testlock' +# work around http://bugs.python.org/issue1515 +if types.MethodType not in copy._deepcopy_dispatch: + def _deepcopy_method(x, memo): + return type(x)(x.im_func, copy.deepcopy(x.im_self, memo), x.im_class) + copy._deepcopy_dispatch[types.MethodType] = _deepcopy_method + class lockwrapper(lock.lock): def __init__(self, pidoffset, *args, **kwargs): # lock.lock.__init__() calls lock(), so the pidoffset assignment needs @@ -128,16 +136,16 @@ class testlock(unittest.TestCase): state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(True) - lock.lock() + # fake a fork - lock.pid += 1 - lock.release() + forklock = copy.deepcopy(lock) + forklock._pidoffset = 1 + forklock.release() state.assertreleasecalled(False) state.assertpostreleasecalled(False) state.assertlockexists(True) # release the actual lock - lock.pid -= 1 lock.release() state.assertreleasecalled(True) state.assertpostreleasecalled(True)