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.
--- a/tests/test-lock.py Thu Sep 24 20:40:00 2015 -0700
+++ b/tests/test-lock.py Thu Sep 24 22:00:51 2015 -0700
@@ -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 @@
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 @@
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)