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): ...@@ -270,18 +270,25 @@ class ClusterPdb(object):
result = last_pdb result = last_pdb
return result return result
def wait(self, test, timeout, period): def wait(self, test, timeout):
end_time = time() + timeout end_time = time() + timeout
period = 0.1
while not test(): while not test():
cluster_dict.acquire() cluster_dict.acquire()
try: try:
last_pdb = self._getLastPdb() last_pdb = self._getLastPdb()
if last_pdb is not None and \ if last_pdb is None:
time() > max(last_pdb + timeout, end_time): 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 return False
finally: finally:
cluster_dict.release() cluster_dict.release()
sleep(period) sleep(next_sleep)
return True return True
__builtin__.pdb = ClusterPdb() __builtin__.pdb = ClusterPdb()
......
...@@ -363,7 +363,7 @@ class NEOCluster(object): ...@@ -363,7 +363,7 @@ class NEOCluster(object):
except NotReadyException: except NotReadyException:
return False return False
return True 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') raise AssertionError('Timeout when starting cluster')
self.port_allocator.reset() self.port_allocator.reset()
...@@ -381,7 +381,7 @@ class NEOCluster(object): ...@@ -381,7 +381,7 @@ class NEOCluster(object):
# more nodes when the cluster restart with an existing partition # more nodes when the cluster restart with an existing partition
# table referencing non-running nodes # table referencing non-running nodes
return len(storage_node_list) >= target_count 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') raise AssertionError('Timeout when starting cluster')
if storage_node_list: if storage_node_list:
self.expectClusterRunning() self.expectClusterRunning()
...@@ -513,7 +513,7 @@ class NEOCluster(object): ...@@ -513,7 +513,7 @@ class NEOCluster(object):
current_try = None current_try = None
return current_try 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 end = time.time() + timeout + DELAY_SAFETY_MARGIN
opaque_history = [None] opaque_history = [None]
def test(): def test():
...@@ -521,7 +521,7 @@ class NEOCluster(object): ...@@ -521,7 +521,7 @@ class NEOCluster(object):
if not reached: if not reached:
opaque_history.append(opaque) opaque_history.append(opaque)
return reached 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] del opaque_history[0]
if on_fail is not None: if on_fail is not None:
on_fail(opaque_history) 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