Bug 1510705 - Fix infinite loop in tests waiting for pending callbacks. r=snorp
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 17 Jan 2019 19:14:06 +0000
changeset 514339 9eb9e58dc4bc3840d7b6b0a414ea4888822356b6
parent 514338 6f0ec77a2d7e09b3900308e30f0770ef1cb3bc9a
child 514340 d08e4acf1e85a899548197db07871a9645935c7e
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1510705
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1510705 - Fix infinite loop in tests waiting for pending callbacks. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D16733
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -1652,21 +1652,33 @@ public class GeckoSessionTestRule implem
             for (final MethodCall call : methodCalls) {
                 assertThat("Cannot wait on null-delegate callbacks",
                            call.method.getDeclaringClass(), not(isIn(mNullDelegates)));
             }
         }
 
         boolean calledAny = false;
         int index = mLastWaitEnd;
+        long startTime = SystemClock.uptimeMillis();
+
         beforeWait();
 
         while (!calledAny || !methodCalls.isEmpty()) {
             while (index >= mCallRecords.size()) {
                 UiThreadUtils.loopUntilIdle(mTimeoutMillis);
+                // We could loop forever here if the UI thread keeps receiving
+                // messages that don't result in any methods being called.
+                // Check whether we've exceeded our allotted time and bail out.
+                if (SystemClock.uptimeMillis() - startTime > mTimeoutMillis) {
+                    break;
+                }
+            }
+
+            if (SystemClock.uptimeMillis() - startTime > mTimeoutMillis) {
+                throw new UiThreadUtils.TimeoutException("Timed out after " + mTimeoutMillis + "ms");
             }
 
             final MethodCall recorded = mCallRecords.get(index).methodCall;
             calledAny |= recorded.method.getDeclaringClass().isAssignableFrom(delegate);
             index++;
 
             final int i = methodCalls.indexOf(recorded);
             if (i < 0) {