test-lock.py: add a lock wrapper that allows faking the PID
authorSiddharth Agarwal <sid0@fb.com>
Thu, 24 Sep 2015 20:22:59 -0700
changeset 26384 ad6e56d01c30
parent 26383 0fceb34806e1
child 26385 fb1a424e8bff
test-lock.py: add a lock wrapper that allows faking the PID This will be used in upcoming patches to create locks that appear as if they're being created by child processes.
tests/test-lock.py
--- a/tests/test-lock.py	Thu Sep 24 21:26:37 2015 -0700
+++ b/tests/test-lock.py	Thu Sep 24 20:22:59 2015 -0700
@@ -12,6 +12,15 @@
 
 testlockname = 'testlock'
 
+class lockwrapper(lock.lock):
+    def __init__(self, pidoffset, *args, **kwargs):
+        # lock.lock.__init__() calls lock(), so the pidoffset assignment needs
+        # to be earlier
+        self._pidoffset = pidoffset
+        super(lockwrapper, self).__init__(*args, **kwargs)
+    def _getpid(self):
+        return os.getpid() + self._pidoffset
+
 class teststate(object):
     def __init__(self, testcase, dir):
         self._testcase = testcase