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 332292 0ed2256fd1fdc19d545c88ec95ad09987321b604
parent 332291 f5f1c014ca19fdff1b98ca14b84fd09c48b02e7c
child 332293 bb565b02a7944724471e6b9443dd102f5784f30c
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1289028
milestone50.0a1
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);
 });