Commit 41c4ce1f authored by Julien Muchembled's avatar Julien Muchembled

tests: new ClusterPdb.sync method to place sync points

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2708 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4621d1b8
...@@ -562,6 +562,12 @@ class ClusterPdb(object): ...@@ -562,6 +562,12 @@ class ClusterPdb(object):
def release(self, delay): def release(self, delay):
os.write(self._w, pack('d', delay)) os.write(self._w, pack('d', delay))
def sync(self):
"""Sleep as long as another process acquires the lock"""
delay = self.acquire()
self.release(delay)
return delay
def interaction(self, hooked, *args, **kw): def interaction(self, hooked, *args, **kw):
delay = self.acquire() - time() delay = self.acquire() - time()
try: try:
...@@ -572,9 +578,7 @@ class ClusterPdb(object): ...@@ -572,9 +578,7 @@ class ClusterPdb(object):
def wait(self, test, timeout, period): def wait(self, test, timeout, period):
end_time = time() + timeout end_time = time() + timeout
while not test(): while not test():
delay = self.acquire() if time() > end_time + self.sync():
self.release(delay)
if time() > end_time + delay:
return False return False
sleep(period) sleep(period)
return True return True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment