Bug 1095426 - neuter the sync scheduler during some tests to avoid oranges. r?kitcambridge draft
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 21 Jun 2017 14:53:07 +1000
changeset 597880 5e2f557136c4a3ecd4e8e766b2f046894f7b843b
parent 597879 b2b74aacf521595fa0101c38c5a84ec17d3b02b5
child 634350 b01a14b5075589f5d651c9d17c138ec8371d2d62
push id65069
push userbmo:markh@mozilla.com
push dateWed, 21 Jun 2017 04:56:58 +0000
reviewerskitcambridge
bugs1095426
milestone56.0a1
Bug 1095426 - neuter the sync scheduler during some tests to avoid oranges. r?kitcambridge MozReview-Commit-ID: Ihun5yu3hit
services/sync/tests/unit/head_helpers.js
--- a/services/sync/tests/unit/head_helpers.js
+++ b/services/sync/tests/unit/head_helpers.js
@@ -467,26 +467,35 @@ function sync_engine_and_validate_telem(
         if (onError) {
           onError(ping.syncs[0], ping);
         }
         reject(caughtError);
       } else {
         resolve(ping.syncs[0]);
       }
     }
-    Svc.Obs.notify("weave:service:sync:start");
+    // neuter the scheduler as it interacts badly with some of the tests - the
+    // engine being synced usually isn't the registered engine, so we see
+    // scored incremented and not removed, which schedules unexpected syncs.
+    let oldObserve = Service.scheduler.observe;
+    Service.scheduler.observe = () => {};
     try {
-      engine.sync();
-    } catch (e) {
-      caughtError = e;
-    }
-    if (caughtError) {
-      Svc.Obs.notify("weave:service:sync:error", caughtError);
-    } else {
-      Svc.Obs.notify("weave:service:sync:finish");
+      Svc.Obs.notify("weave:service:sync:start");
+      try {
+        engine.sync();
+      } catch (e) {
+        caughtError = e;
+      }
+      if (caughtError) {
+        Svc.Obs.notify("weave:service:sync:error", caughtError);
+      } else {
+        Svc.Obs.notify("weave:service:sync:finish");
+      }
+    } finally {
+      Service.scheduler.observe = oldObserve;
     }
   });
 }
 
 // Returns a promise that resolves once the specified observer notification
 // has fired.
 function promiseOneObserver(topic, callback) {
   return new Promise((resolve, reject) => {