[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/forker.py Added a helper function to wait until something is true.

Jim Fulton jim at zope.com
Thu Dec 18 19:41:52 EST 2008


Log message for revision 94179:
  Added a helper function to wait until something is true.
  

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

-=-
Modified: ZODB/trunk/src/ZEO/tests/forker.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/forker.py	2008-12-19 00:41:51 UTC (rev 94178)
+++ ZODB/trunk/src/ZEO/tests/forker.py	2008-12-19 00:41:52 UTC (rev 94179)
@@ -326,20 +326,21 @@
     test.globs['wait_connected'] = wait_connected
     test.globs['wait_disconnected'] = wait_disconnected
 
-def wait_connected(storage):
+
+def wait_until(func, timeout=30, label=None):
+    if not label:
+        label = func.__name__
     now = time.time()
     giveup = now + 30
-    while not storage.is_connected():
+    while not func():
         now = time.time()
         if time.time() > giveup:
-            raise AssertionError("timed out waiting for storage to connect")
-        time.sleep(0.1)
+            raise AssertionError("Timed out waiting for", label)
+        time.sleep(0.01)
+        
+def wait_connected(storage):
+    wait_until(storage.is_connected)
 
 def wait_disconnected(storage):
-    now = time.time()
-    giveup = now + 30
-    while storage.is_connected():
-        now = time.time()
-        if time.time() > giveup:
-            raise AssertionError("timed out waiting for storage to connect")
-        time.sleep(0.1)
+    def not_connected():
+        return not storage.is_connected()



More information about the Zodb-checkins mailing list