Skip to content

Commit

Permalink
Merge "Allow to specify TimeoutError text in wait"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jun 17, 2015
2 parents abf2680 + f004e8e commit e6f74ba
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions devops/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def tcp_ping(host, port):
return True


def wait(predicate, interval=5, timeout=60):
"""wait until predicate will become True.
def wait(predicate, interval=5, timeout=60, timeout_msg="Waiting timed out"):
"""Wait until predicate will become True.
returns number of seconds that is left or 0 if timeout is None.
Expand All @@ -89,13 +89,15 @@ def wait(predicate, interval=5, timeout=60):
timeout - raise TimeoutError if predicate won't become True after
this amount of seconds. 'None' disables timeout.
timeout_msg - text of the TimeoutError
"""
start_time = time.time()
if not timeout:
return predicate()
while not predicate():
if start_time + timeout < time.time():
raise TimeoutError("Waiting timed out")
raise TimeoutError(timeout_msg)

seconds_to_sleep = max(
0,
Expand Down

0 comments on commit e6f74ba

Please sign in to comment.