lock: add a wrapper to os.getpid() to make testing easier
This will allow us to fake locks across processes more easily.
--- 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: