Commit dcace4ee authored by Julien Muchembled's avatar Julien Muchembled

tests: slightly speed up cluster startup & expectXxx methods

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2742 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 3db30547
......@@ -270,18 +270,25 @@ class ClusterPdb(object):
result = last_pdb
return result
def wait(self, test, timeout, period):
def wait(self, test, timeout):
end_time = time() + timeout
period = 0.1
while not test():
cluster_dict.acquire()
try:
last_pdb = self._getLastPdb()
if last_pdb is not None and \
time() > max(last_pdb + timeout, end_time):
return False
if last_pdb is None:
next_sleep = 1
else:
next_sleep = max(last_pdb + timeout, end_time) - time()
if next_sleep > period:
next_sleep = period
period *= 1.5
elif next_sleep < 0:
return False
finally:
cluster_dict.release()
sleep(period)
sleep(next_sleep)
return True
__builtin__.pdb = ClusterPdb()
......
......@@ -363,7 +363,7 @@ class NEOCluster(object):
except NotReadyException:
return False
return True
if not pdb.wait(test, MAX_START_TIME, 0.5):
if not pdb.wait(test, MAX_START_TIME):
raise AssertionError('Timeout when starting cluster')
self.port_allocator.reset()
......@@ -381,7 +381,7 @@ class NEOCluster(object):
# more nodes when the cluster restart with an existing partition
# table referencing non-running nodes
return len(storage_node_list) >= target_count
if not pdb.wait(test, MAX_START_TIME, 0.5):
if not pdb.wait(test, MAX_START_TIME):
raise AssertionError('Timeout when starting cluster')
if storage_node_list:
self.expectClusterRunning()
......@@ -513,7 +513,7 @@ class NEOCluster(object):
current_try = None
return current_try
def expectCondition(self, condition, timeout=0, delay=.5, on_fail=None):
def expectCondition(self, condition, timeout=0, on_fail=None):
end = time.time() + timeout + DELAY_SAFETY_MARGIN
opaque_history = [None]
def test():
......@@ -521,7 +521,7 @@ class NEOCluster(object):
if not reached:
opaque_history.append(opaque)
return reached
if not pdb.wait(test, timeout + DELAY_SAFETY_MARGIN, delay):
if not pdb.wait(test, timeout + DELAY_SAFETY_MARGIN):
del opaque_history[0]
if on_fail is not None:
on_fail(opaque_history)
......
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