Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: client/bin/site_utils.py

Issue 1534001: switch to autox.py and robustify login/logout code (Closed)
Patch Set: merge with head Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/bin/site_ui_test.py ('k') | client/common_lib/site_ui.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/bin/site_utils.py
diff --git a/client/bin/site_utils.py b/client/bin/site_utils.py
index 50a0bdff94cd94ad048e6f0cdfeebf0771f0292e..2e3caf3c7fe818bccc577527f77de3a97dcafa8a 100644
--- a/client/bin/site_utils.py
+++ b/client/bin/site_utils.py
@@ -6,23 +6,35 @@ import time
from autotest_lib.client.common_lib import error
+class TimeoutError(error.TestError):
+ """Error raised when we time out when waiting on a condition."""
+
+
def poll_for_condition(
- condition, exception=None, timeout=10, sleep_interval=0.1):
+ condition, exception=None, timeout=10, sleep_interval=0.1, desc=None):
"""Poll until a condition becomes true.
condition: function taking no args and returning bool
exception: exception to throw if condition doesn't become true
timeout: maximum number of seconds to wait
sleep_interval: time to sleep between polls
+ desc: description of default TimeoutError used if 'exception' is None
Raises:
- 'exception' arg if supplied; error.TestError otherwise
+ 'exception' arg if supplied; site_utils.TimeoutError otherwise
"""
start_time = time.time()
while True:
if condition():
return
if time.time() + sleep_interval - start_time > timeout:
- raise exception if exception else error.TestError(
- 'Timed out waiting for condition')
+ if exception:
+ raise exception
+
+ if desc:
+ desc = 'Timed out waiting for condition: %s' % desc
+ else:
+ desc = 'Timed out waiting for unnamed condition'
+ raise error.TestError(desc)
+
time.sleep(sleep_interval)
« no previous file with comments | « client/bin/site_ui_test.py ('k') | client/common_lib/site_ui.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698