changeset 26386:146cccdb282b

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.
author Siddharth Agarwal <sid0@fb.com>
date Thu, 24 Sep 2015 22:00:51 -0700
parents fb1a424e8bff
children e16f80f89a29
files tests/test-lock.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)