Patchwork [4,of,7] test-lock.py: add a lock wrapper that allows faking the PID

login
register
mail settings
Submitter Siddharth Agarwal
Date Sept. 25, 2015, 7 p.m.
Message ID <4c629e4a785b733bea31.1443207638@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10638/
State Accepted
Headers show

Comments

Siddharth Agarwal - Sept. 25, 2015, 7 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1443151379 25200
#      Thu Sep 24 20:22:59 2015 -0700
# Node ID 4c629e4a785b733bea314505fbdbe70704b704ba
# Parent  2c888bfeabe740a6f261d0a89091592964ea4f0d
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.

Patch

diff --git a/tests/test-lock.py b/tests/test-lock.py
--- a/tests/test-lock.py
+++ b/tests/test-lock.py
@@ -12,6 +12,15 @@  from mercurial import (
 
 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