changeset 26383:0fceb34806e1

lock: add a wrapper to os.getpid() to make testing easier This will allow us to fake locks across processes more easily.
author Siddharth Agarwal <sid0@fb.com>
date Thu, 24 Sep 2015 21:26:37 -0700
parents b673e89affc9
children ad6e56d01c30
files mercurial/lock.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/lock.py	Thu Sep 24 19:52:34 2015 -0700
+++ b/mercurial/lock.py	Thu Sep 24 21:26:37 2015 -0700
@@ -51,7 +51,7 @@
         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 @@
 
         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 @@
             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: