Bug 957162 - Marionette Wait's should indicate timeout duration. r=davehunt

This commit is contained in:
Andreas Tolfsen 2014-01-08 16:06:05 -05:00
parent 84a856ea5d
commit 4f0de9f668
2 changed files with 9 additions and 3 deletions

View File

@ -209,3 +209,8 @@ class WaitUntilTest(MarionetteTestCase):
self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt)
self.assertEqual(self.clock.ticks, 2)
def test_timeout_elapsed_duration(self):
with self.assertRaisesRegexp(errors.TimeoutException,
"Timed out after 2 seconds"):
self.w.until(lambda x: x.true(wait=4), is_true=at_third_attempt)

View File

@ -40,7 +40,7 @@ class Wait(object):
# every 5 seconds.
wait = Wait(marionette, timeout=30, interval=5,
ignored_exceptions=errors.NoSuchWindowException)
window = wait.until(lambda marionette: marionette.switch_to_window(42))
window = wait.until(lambda m: m.switch_to_window(42))
:param marionette: The input value to be provided to
conditions, usually a Marionette instance.
@ -78,7 +78,6 @@ class Wait(object):
exceptions.append(ignored_exceptions)
self.exceptions = tuple(set(exceptions))
def until(self, condition, is_true=None):
"""Repeatedly runs condition until its return value evaluates to true,
or its timeout expires or the predicate evaluates to true.
@ -109,6 +108,7 @@ class Wait(object):
rv = None
last_exc = None
until = is_true or until_pred
start = self.clock.now
while not until(self.clock, self.end):
try:
@ -130,7 +130,8 @@ class Wait(object):
if last_exc is not None:
raise last_exc
raise errors.TimeoutException
raise errors.TimeoutException(
"Timed out after %s seconds" % (self.clock.now - start))
def until_pred(clock, end):
return clock.now >= end