[Neo-report] r2742 jm - in /trunk/neo/tests: cluster.py functional/__init__.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 28 21:46:57 CEST 2011


Author: jm
Date: Thu Apr 28 21:46:57 2011
New Revision: 2742

Log:
tests: slightly speed up cluster startup & expectXxx methods

Modified:
    trunk/neo/tests/cluster.py
    trunk/neo/tests/functional/__init__.py

Modified: trunk/neo/tests/cluster.py
==============================================================================
--- trunk/neo/tests/cluster.py [iso-8859-1] (original)
+++ trunk/neo/tests/cluster.py [iso-8859-1] Thu Apr 28 21:46:57 2011
@@ -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()

Modified: trunk/neo/tests/functional/__init__.py
==============================================================================
--- trunk/neo/tests/functional/__init__.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/__init__.py [iso-8859-1] Thu Apr 28 21:46:57 2011
@@ -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)




More information about the Neo-report mailing list