Bug 1289028 - Retry when url-classifier test_gethash.html hits an exception. r=francois
authorDimi Lee <dlee@mozilla.com>
Fri, 29 Jul 2016 08:21:01 +0800
changeset 347258 0ed2256fd1fdc19d545c88ec95ad09987321b604
parent 347257 f5f1c014ca19fdff1b98ca14b84fd09c48b02e7c
child 347259 bb565b02a7944724471e6b9443dd102f5784f30c
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1289028
milestone50.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 1289028 - Retry when url-classifier test_gethash.html hits an exception. r=francois MozReview-Commit-ID: 9BR7RfAthcU
toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
--- a/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
+++ b/toolkit/components/url-classifier/tests/mochitest/classifierCommon.js
@@ -1,11 +1,20 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const { classes: Cc, interfaces: Ci, results: Cr } = Components;
+
+function setTimeout(callback, delay) {
+  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+  timer.initWithCallback({ notify: callback },
+                           delay,
+                           Ci.nsITimer.TYPE_ONE_SHOT);
+}
+
 function doUpdate(update) {
   const { classes: Cc, interfaces: Ci, results: Cr } = Components;
 
   let listener = {
     QueryInterface: function(iid)
     {
       if (iid.equals(Ci.nsISupports) ||
           iid.equals(Ci.nsIUrlClassifierUpdateObserver))
@@ -21,18 +30,24 @@ function doUpdate(update) {
     updateSuccess: function(requestedTimeout) {
       sendAsyncMessage("updateSuccess");
     }
   };
 
   let dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
                   .getService(Ci.nsIUrlClassifierDBService);
 
-  dbService.beginUpdate(listener, "test-malware-simple,test-unwanted-simple", "");
-  dbService.beginStream("", "");
-  dbService.updateStream(update);
-  dbService.finishStream();
-  dbService.finishUpdate();
+  try {
+    dbService.beginUpdate(listener, "test-malware-simple,test-unwanted-simple", "");
+    dbService.beginStream("", "");
+    dbService.updateStream(update);
+    dbService.finishStream();
+    dbService.finishUpdate();
+  } catch(e) {
+    // beginUpdate may fail if there's an existing update in progress
+    // retry until success or testcase timeout.
+    setTimeout(() => { doUpdate(update); }, 1000);
+  }
 }
 
 addMessageListener("doUpdate", ({ testUpdate }) => {
   doUpdate(testUpdate);
 });