--- a/tests/test-lock.py Tue Sep 22 13:25:41 2015 -0700
+++ b/tests/test-lock.py Tue Sep 22 14:09:42 2015 -0700
@@ -15,23 +15,38 @@
class teststate(object):
def __init__(self, testcase):
self._testcase = testcase
+ self._acquirecalled = False
self._releasecalled = False
self._postreleasecalled = False
d = tempfile.mkdtemp(dir=os.getcwd())
self.vfs = scmutil.vfs(d, audit=False)
def makelock(self, *args, **kwargs):
- l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn, *args,
- **kwargs)
+ l = lock.lock(self.vfs, testlockname, releasefn=self.releasefn,
+ acquirefn=self.acquirefn, *args, **kwargs)
l.postrelease.append(self.postreleasefn)
return l
+ def acquirefn(self):
+ self._acquirecalled = True
+
def releasefn(self):
self._releasecalled = True
def postreleasefn(self):
self._postreleasecalled = True
+ def assertacquirecalled(self, called):
+ self._testcase.assertEqual(
+ self._acquirecalled, called,
+ 'expected acquire to be %s but was actually %s' % (
+ self._tocalled(called),
+ self._tocalled(self._acquirecalled),
+ ))
+
+ def resetacquirefn(self):
+ self._acquirecalled = False
+
def assertreleasecalled(self, called):
self._testcase.assertEqual(
self._releasecalled, called,
@@ -73,6 +88,7 @@
def testlock(self):
state = teststate(self)
lock = state.makelock()
+ state.assertacquirecalled(True)
lock.release()
state.assertreleasecalled(True)
state.assertpostreleasecalled(True)
@@ -81,7 +97,13 @@
def testrecursivelock(self):
state = teststate(self)
lock = state.makelock()
+ state.assertacquirecalled(True)
+
+ state.resetacquirefn()
lock.lock()
+ # recursive lock should not call acquirefn again
+ state.assertacquirecalled(False)
+
lock.release() # brings lock refcount down from 2 to 1
state.assertreleasecalled(False)
state.assertpostreleasecalled(False)
@@ -95,6 +117,7 @@
def testlockfork(self):
state = teststate(self)
lock = state.makelock()
+ state.assertacquirecalled(True)
lock.lock()
# fake a fork
lock.pid += 1