Bug 957162 - Marionette Wait's should indicate timeout duration. r=davehunt, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Wed, 08 Jan 2014 16:06:05 -0500
changeset 167938 5931195ee9578dc03296f5548ca00faedaa4579d
parent 167937 bbe4c142c923f529d0aa77e53094526c3152952b
child 167939 3fe1886a46c81dc90ebfc6766d19a57d9d2b5231
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavehunt, test-only
Bug 957162 - Marionette Wait's should indicate timeout duration. r=davehunt, a=test-only
--- a/testing/marionette/client/marionette/tests/unit/test_wait.py
+++ b/testing/marionette/client/marionette/tests/unit/test_wait.py
@@ -204,8 +204,13 @@ class WaitUntilTest(MarionetteTestCase):
         self.assertEqual(self.clock.ticks, 1)
     def test_custom_predicate_times_out(self):
         with self.assertRaises(errors.TimeoutException):
             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)
--- a/testing/marionette/client/marionette/wait.py
+++ b/testing/marionette/client/marionette/wait.py
@@ -35,17 +35,17 @@ class Wait(object):
         (time) can also be provided.
         Sample usage:
             # Wait 30 seconds for window to open, checking for its presence once
             # every 5 seconds.
             wait = Wait(marionette, timeout=30, interval=5,
-            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.
         :param timeout: How long to wait for the evaluated condition
             to become true.  The default time is wait.DEFAULT_TIMEOUT.
         :param interval: How often the condition should be evaluated.
@@ -73,17 +73,16 @@ class Wait(object):
         exceptions = []
         if ignored_exceptions is not None:
             if isinstance(ignored_exceptions, collections.Iterable):
         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.
         This will poll at the given interval until the given timeout
         is reached, or the predicate or conditions returns true.  A
         condition that returns null or does not evaluate to true will
         fully elapse its timeout before raising an
@@ -104,16 +103,17 @@ class Wait(object):
             predicate will terminate a wait when the clock elapses the
         rv = None
         last_exc = None
         until = is_true or until_pred
+        start = self.clock.now
         while not until(self.clock, self.end):
                 rv = condition(self.marionette)
             except (KeyboardInterrupt, SystemExit) as e:
                 raise e
             except self.exceptions as e:
                 last_exc = e
@@ -125,17 +125,18 @@ class Wait(object):
             if rv is not None:
                 return rv
         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
 class SystemClock(object):
     def __init__(self):
         self._time = time