Bug 676042 - Track Clients engine score in global sync score; r=philikon
authorGregory Szorc <gps@mozilla.com>
Tue, 09 Aug 2011 09:25:12 -0700
changeset 77024 7550224fb6c1b689f0a4772b92e46be432b31b93
parent 77023 0815c4e5b498ec351363d982d886a67a8e47f6f3
child 77025 6ec6c57945f0566bbea447949be2ff809efcbe32
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs676042
milestone8.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 676042 - Track Clients engine score in global sync score; r=philikon
services/sync/modules/policies.js
services/sync/tests/unit/test_score_triggers.js
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -231,17 +231,17 @@ let SyncScheduler = {
       this.syncInterval = this.immediateInterval;
     } else {
       this._log.trace("Adjusting syncInterval to activeInterval.");
       this.syncInterval = this.activeInterval;
     }
   },
 
   calculateScore: function calculateScore() {
-    var engines = Engines.getEnabled();
+    let engines = [Clients].concat(Engines.getEnabled());
     for (let i = 0;i < engines.length;i++) {
       this._log.trace(engines[i].name + ": score: " + engines[i].score);
       this.globalScore += engines[i].score;
       engines[i]._tracker.resetScore();
     }
 
     this._log.trace("Global score updated: " + this.globalScore);
     this.checkSyncStatus();
--- a/services/sync/tests/unit/test_score_triggers.js
+++ b/services/sync/tests/unit/test_score_triggers.js
@@ -1,12 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 Cu.import("resource://services-sync/engines.js");
+Cu.import("resource://services-sync/engines/clients.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/policies.js");
 
 Svc.DefaultPrefs.set("registerEngines", "");
 Cu.import("resource://services-sync/service.js");
 
 Engines.register(RotaryEngine);
 let engine = Engines.get("rotary");
@@ -90,8 +91,30 @@ add_test(function test_sync_triggered() 
     Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
     _("Sync completed!");
     server.stop(run_next_test);
   });
 
   tracker.score += SCORE_INCREMENT_XLARGE;
 });
 
+add_test(function test_clients_engine_sync_triggered() {
+  _("Ensure that client engine score changes trigger a sync.");
+
+  // The clients engine is not registered like other engines. Therefore,
+  // it needs special treatment throughout the code. Here, we verify the
+  // global score tracker gives it that treatment. See bug 676042 for more.
+
+  let server = sync_httpd_setup();
+  setUp();
+  Service.login();
+
+  const TOPIC = "weave:service:sync:finish";
+  Svc.Obs.add(TOPIC, function onSyncFinish() {
+    Svc.Obs.remove(TOPIC, onSyncFinish);
+    _("Sync due to clients engine change completed.");
+    server.stop(run_next_test);
+  });
+
+  SyncScheduler.syncThreshold = MULTI_DEVICE_THRESHOLD;
+  Clients._tracker.score += SCORE_INCREMENT_XLARGE;
+});
+