Backed out changeset ffc59a6dfbd5 (bug 1595285) for bc failures at browser_editBookmark_tags_liveUpdate.js. CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Wed, 13 Nov 2019 18:03:55 +0200
changeset 501757 2c748c06bd9b294017bd5b5d6b0967b86b580d7c
parent 501756 35f2efaaeff6d8c617498ba1958a2409efe1c92c
child 501758 76886efb06b40b8b9934f15e34150335c46c9c82
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1595285
milestone72.0a1
backs outffc59a6dfbd58dcc28114acc38a7ef29f55d0aab
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
Backed out changeset ffc59a6dfbd5 (bug 1595285) for bc failures at browser_editBookmark_tags_liveUpdate.js. CLOSED TREE
testing/modules/TestUtils.jsm
--- a/testing/modules/TestUtils.jsm
+++ b/testing/modules/TestUtils.jsm
@@ -16,17 +16,19 @@
  * example LoginTestUtils.jsm.
  */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["TestUtils"];
 
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
-const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
+const { clearInterval, setInterval } = ChromeUtils.import(
+  "resource://gre/modules/Timer.jsm"
+);
 
 var TestUtils = {
   executeSoon(callbackFn) {
     Services.tm.dispatchToMainThread(callbackFn);
   },
 
   waitForTick() {
     return new Promise(resolve => this.executeSoon(resolve));
@@ -156,48 +158,44 @@ var TestUtils = {
    *        to 100ms.
    * @param attempts
    *        The number of times to poll before giving up and rejecting
    *        if the condition has not yet returned true. Defaults to 50
    *        (~5 seconds for 100ms intervals)
    * @return Promise
    *        Resolves with the return value of the condition function.
    *        Rejects if timeout is exceeded or condition ever throws.
-   *
-   * NOTE: This is intentionally not using setInterval, using setTimeout
-   * instead. setInterval is not promise-safe.
    */
   waitForCondition(condition, msg, interval = 100, maxTries = 50) {
     return new Promise((resolve, reject) => {
       let tries = 0;
-      async function tryOnce() {
+      let intervalID = setInterval(async function() {
         if (tries >= maxTries) {
+          clearInterval(intervalID);
           msg += ` - timed out after ${maxTries} tries.`;
           reject(msg);
           return;
         }
 
         let conditionPassed = false;
         try {
           conditionPassed = await condition();
         } catch (e) {
           msg += ` - threw exception: ${e}`;
+          clearInterval(intervalID);
           reject(msg);
           return;
         }
 
         if (conditionPassed) {
+          clearInterval(intervalID);
           resolve(conditionPassed);
-          return;
         }
         tries++;
-        setTimeout(tryOnce, interval);
-      }
-
-      tryOnce();
+      }, interval);
     });
   },
 
   shuffle(array) {
     let results = [];
     for (let i = 0; i < array.length; ++i) {
       let randomIndex = Math.floor(Math.random() * (i + 1));
       results[i] = results[randomIndex];