def WaitUntil(predicate, timeout_seconds=1):
"""Blocks until the provided predicate (function) is true.
Returns:
Whether the provided predicate was satisfied once (before the timeout).
"""
start_time = time.clock()
sleep_time_sec = 0.025
while True:
if predicate():
return True
if time.clock() - start_time > timeout_seconds:
return False
time.sleep(sleep_time_sec)
sleep_time_sec = min(1, sleep_time_sec * 2) # Don't wait more than 1 sec.
# Implementation of chrome_test_server_spawner.PortForwarder that doesn't
# forward ports. Instead the tests are expected to connect to the host IP
# address inside the virtual network provided by qemu. qemu will forward
# these connections to the corresponding localhost ports.
评论列表
文章目录