Commit b43c3f1a authored by Jim Fulton's avatar Jim Fulton

Added a helper function to wait until something is true.

parent bb047cfc
...@@ -326,20 +326,21 @@ def setUp(test): ...@@ -326,20 +326,21 @@ def setUp(test):
test.globs['wait_connected'] = wait_connected test.globs['wait_connected'] = wait_connected
test.globs['wait_disconnected'] = wait_disconnected 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() now = time.time()
giveup = now + 30 giveup = now + 30
while not storage.is_connected(): while not func():
now = time.time() now = time.time()
if time.time() > giveup: if time.time() > giveup:
raise AssertionError("timed out waiting for storage to connect") raise AssertionError("Timed out waiting for", label)
time.sleep(0.1) time.sleep(0.01)
def wait_connected(storage):
wait_until(storage.is_connected)
def wait_disconnected(storage): def wait_disconnected(storage):
now = time.time() def not_connected():
giveup = now + 30 return not storage.is_connected()
while storage.is_connected():
now = time.time()
if time.time() > giveup:
raise AssertionError("timed out waiting for storage to connect")
time.sleep(0.1)
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