[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/forker.py Added an onfail argument to wait_until to provide alternate behavior

Jim Fulton jim at zope.com
Fri Jun 5 18:53:38 EDT 2009


Log message for revision 100660:
  Added an onfail argument to wait_until to provide alternate behavior
  for a timeout.
  

Changed:
  U   ZODB/trunk/src/ZEO/tests/forker.py

-=-
Modified: ZODB/trunk/src/ZEO/tests/forker.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/forker.py	2009-06-05 22:30:43 UTC (rev 100659)
+++ ZODB/trunk/src/ZEO/tests/forker.py	2009-06-05 22:53:38 UTC (rev 100660)
@@ -137,7 +137,7 @@
         args.append("-S")
     if protocol:
         args.extend(["-v", protocol])
-        
+
     d = os.environ.copy()
     d['PYTHONPATH'] = os.pathsep.join(sys.path)
 
@@ -222,7 +222,7 @@
 
     if test is not None:
         return get_port2(test)
-    
+
     for i in range(10):
         port = random.randrange(20000, 30000)
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -281,7 +281,7 @@
     else:
         c.close()
         return True
-    
+
 def setUp(test):
     ZODB.tests.util.setUp(test)
 
@@ -330,13 +330,14 @@
     test.globs['wait_disconnected'] = wait_disconnected
 
 
-def wait_until(label, func, timeout=30):
-    now = time.time()
-    giveup = now + 30
+def wait_until(label, func, timeout=30, onfail=None):
+    giveup = time.time() + timeout
     while not func():
-        now = time.time()
         if time.time() > giveup:
-            raise AssertionError("Timed out waiting for: ", label)
+            if onfail is None:
+                raise AssertionError("Timed out waiting for: ", label)
+            else:
+                return onfail()
         time.sleep(0.01)
 
 def wait_connected(storage):



More information about the Zodb-checkins mailing list