Commit bee97cf1 authored by Jim Fulton's avatar Jim Fulton

Added an onfail argument to wait_until to provide alternate behavior

for a timeout.
parent 04581d75
...@@ -137,7 +137,7 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False, ...@@ -137,7 +137,7 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
args.append("-S") args.append("-S")
if protocol: if protocol:
args.extend(["-v", protocol]) args.extend(["-v", protocol])
d = os.environ.copy() d = os.environ.copy()
d['PYTHONPATH'] = os.pathsep.join(sys.path) d['PYTHONPATH'] = os.pathsep.join(sys.path)
...@@ -222,7 +222,7 @@ def get_port(test=None): ...@@ -222,7 +222,7 @@ def get_port(test=None):
if test is not None: if test is not None:
return get_port2(test) return get_port2(test)
for i in range(10): for i in range(10):
port = random.randrange(20000, 30000) port = random.randrange(20000, 30000)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
...@@ -281,7 +281,7 @@ def can_connect(port): ...@@ -281,7 +281,7 @@ def can_connect(port):
else: else:
c.close() c.close()
return True return True
def setUp(test): def setUp(test):
ZODB.tests.util.setUp(test) ZODB.tests.util.setUp(test)
...@@ -330,13 +330,14 @@ def setUp(test): ...@@ -330,13 +330,14 @@ def setUp(test):
test.globs['wait_disconnected'] = wait_disconnected test.globs['wait_disconnected'] = wait_disconnected
def wait_until(label, func, timeout=30): def wait_until(label, func, timeout=30, onfail=None):
now = time.time() giveup = time.time() + timeout
giveup = now + 30
while not func(): while not func():
now = time.time()
if time.time() > giveup: 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) time.sleep(0.01)
def wait_connected(storage): def wait_connected(storage):
......
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