Bug 1229250 - Auto-extend the reftest timeout - r=kats
authorEdwin Flores <eflores@mozilla.com>
Tue, 16 Feb 2016 14:46:56 +0000
changeset 331298 46180e3cd0c6adda64977bd6ecd82aec201d6f3a
parent 331297 04972721d1fbfbe8365ddf5b8c1f7423f863303d
child 331299 a3f46ba96f9572ad00ce1190f3b22a55117de8fe
push id10956
push userjolesen@mozilla.com
push dateTue, 16 Feb 2016 19:12:12 +0000
reviewerskats
bugs1229250
milestone47.0a1
Bug 1229250 - Auto-extend the reftest timeout - r=kats
layout/tools/reftest/reftest-content.js
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -114,16 +114,34 @@ function OnInitialLoad()
     addEventListener("load", OnDocumentLoad, true);
 
     addEventListener("MozPaintWait", PaintWaitListener, true);
     addEventListener("MozPaintWaitFinished", PaintWaitFinishedListener, true);
 
     LogWarning("Using browser remote="+ gBrowserIsRemote +"\n");
 }
 
+function SetFailureTimeout(cb, timeout)
+{
+  var targetTime = Date.now() + timeout;
+
+  var wrapper = function() {
+    // Timeouts can fire prematurely in some cases (e.g. in chaos mode). If this
+    // happens, set another timeout for the remaining time.
+    let remainingMs = targetTime - Date.now();
+    if (remainingMs > 0) {
+      SetFailureTimeout(cb, remainingMs);
+    } else {
+      cb();
+    }
+  }
+
+  gFailureTimeout = setTimeout(wrapper, timeout);
+}
+
 function StartTestURI(type, uri, timeout)
 {
     // Reset gExplicitPendingPaintCount in case there was a timeout or
     // the count is out of sync for some other reason
     if (gExplicitPendingPaintCount != 0) {
         LogWarning("Resetting gExplicitPendingPaintCount to zero (currently " +
                    gExplicitPendingPaintCount + "\n");
         gExplicitPendingPaintCount = 0;
@@ -131,17 +149,17 @@ function StartTestURI(type, uri, timeout
 
     gCurrentTestType = type;
     gCurrentURL = uri;
 
     gCurrentTestStartTime = Date.now();
     if (gFailureTimeout != null) {
         SendException("program error managing timeouts\n");
     }
-    gFailureTimeout = setTimeout(LoadFailed, timeout);
+    SetFailureTimeout(LoadFailed, timeout);
 
     LoadURI(gCurrentURL);
 }
 
 function setupFullZoom(contentRootElement) {
     if (!contentRootElement || !contentRootElement.hasAttribute('reftest-zoom'))
         return;
     markupDocumentViewer().fullZoom =