Patchwork [3,of,7] lock: add a wrapper to os.getpid() to make testing easier

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

Comments

Siddharth Agarwal - Sept. 25, 2015, 7 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1443155197 25200
#      Thu Sep 24 21:26:37 2015 -0700
# Node ID 2c888bfeabe740a6f261d0a89091592964ea4f0d
# Parent  2b835a6b40b64223f4771c89e888fbd8837ecbf7
lock: add a wrapper to os.getpid() to make testing easier

This will allow us to fake locks across processes more easily.

Patch

diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -51,7 +51,7 @@  class lock(object):
         self._parentheld = False
         self._inherited = False
         self.postrelease  = []
-        self.pid = os.getpid()
+        self.pid = self._getpid()
         self.delay = self.lock()
         if self.acquirefn:
             self.acquirefn()
@@ -68,6 +68,10 @@  class lock(object):
 
         self.release()
 
+    def _getpid(self):
+        # wrapper around os.getpid() to make testing easier
+        return os.getpid()
+
     def lock(self):
         timeout = self.timeout
         while True:
@@ -197,7 +201,7 @@  class lock(object):
             self.held -= 1
         elif self.held == 1:
             self.held = 0
-            if os.getpid() != self.pid:
+            if self._getpid() != self.pid:
                 # we forked, and are not the parent
                 return
             try: