From 9a60c4ff8c3c06fef8923342e803f9565f47f738 Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Mon, 29 Sep 2014 13:05:23 -0700 Subject: [PATCH] Bug 1071920 - Make sure we don't time out incorrectly with chaos mode (r=roc) --- testing/mochitest/browser-test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing/mochitest/browser-test.js b/testing/mochitest/browser-test.js index 59090fc2588..93049f06bc7 100644 --- a/testing/mochitest/browser-test.js +++ b/testing/mochitest/browser-test.js @@ -676,7 +676,18 @@ Tester.prototype = { } else { var self = this; + var timeoutExpires = Date.now() + gTimeoutSeconds * 1000; + var waitUntilAtLeast = timeoutExpires - 1000; this.currentTest.scope.__waitTimer = setTimeout(function timeoutFn() { + // We sometimes get woken up long before the gTimeoutSeconds + // have elapsed (when running in chaos mode for example). This + // code ensures that we don't wrongly time out in that case. + if (Date.now() < waitUntilAtLeast) { + self.currentTest.scope.__waitTimer = + setTimeout(timeoutFn, timeoutExpires - Date.now()); + return; + } + if (--self.currentTest.scope.__timeoutFactor > 0) { // We were asked to wait a bit longer. self.currentTest.scope.info(