Bug 1374599 - 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 597882 37357897b9d859943fd237f3534c5c4555b01448
parent 597879 b2b74aacf521595fa0101c38c5a84ec17d3b02b5
child 634352 78e07f50787f9854f02703e164cf722cda33c51e
push id65071
push userbmo:markh@mozilla.com
push dateWed, 21 Jun 2017 04:58:46 +0000
reviewerskitcambridge
bugs1374599
milestone56.0a1
Bug 1374599 - 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) => {