[PATCH 6 of 7] test-lock.py: fix testing for forks
Siddharth Agarwal
sid0 at fb.com
Fri Sep 25 14:00:40 CDT 2015
# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1443157251 25200
# Thu Sep 24 22:00:51 2015 -0700
# Node ID 5049d8ab47a936227186493f7de27a2bea35d627
# Parent bb88105b0fe118eea54e8043b999f9c813895bfa
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)
More information about the Mercurial-devel
mailing list