Bug 1317579 - Don't send a sync ping for self-hosters. r=tcsc
authorKit Cambridge <kit@yakshaving.ninja>
Thu, 22 Dec 2016 19:00:34 -0700
changeset 374967 35ae28472a13c11da225302473849ab037ee3611
parent 374916 232825e23296e9dad742ab85de15910d9ab2d4fe
child 374968 6ba01b40808abb8fdcab6c18ddcbb8b7dc25edb5
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcsc
bugs1317579
milestone53.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 1317579 - Don't send a sync ping for self-hosters. r=tcsc MozReview-Commit-ID: 601nfXW0gT6
services/sync/modules/telemetry.js
services/sync/tests/unit/test_telemetry.js
--- a/services/sync/modules/telemetry.js
+++ b/services/sync/modules/telemetry.js
@@ -496,22 +496,28 @@ class SyncTelemetryImpl {
   shutdown() {
     this.finish("shutdown");
     for (let topic of TOPICS) {
       Observers.remove(topic, this, this);
     }
   }
 
   submit(record) {
+    if (Services.prefs.prefHasUserValue("identity.sync.tokenserver.uri")) {
+      log.trace(`Not sending telemetry ping for self-hosted Sync user`);
+      return false;
+    }
     // We still call submit() with possibly illegal payloads so that tests can
     // know that the ping was built. We don't end up submitting them, however.
     if (record.syncs.length) {
       log.trace(`submitting ${record.syncs.length} sync record(s) to telemetry`);
       TelemetryController.submitExternalPing("sync", record);
+      return true;
     }
+    return false;
   }
 
 
   onSyncStarted() {
     if (this.current) {
       log.warn("Observed weave:service:sync:start, but we're already recording a sync!");
       // Just discard the old record, consistent with our handling of engines, above.
       this.current = null;
--- a/services/sync/tests/unit/test_telemetry.js
+++ b/services/sync/tests/unit/test_telemetry.js
@@ -667,8 +667,40 @@ add_task(async function test_invalid_eve
       badextra["name" + i] = "x";
     }
     await checkNotRecorded("object", "method", "value", badextra);
   } finally {
     Service.engineManager.unregister(engine);
     await cleanAndGo(engine, server);
   }
 });
+
+add_task(async function test_no_ping_for_self_hosters() {
+  let telem = get_sync_test_telemetry();
+  let oldSubmit = telem.submit;
+
+  Service.engineManager.register(BogusEngine);
+  let engine = Service.engineManager.get("bogus");
+  engine.enabled = true;
+  let server = serverForUsers({"foo": "password"}, {
+    meta: {global: {engines: {bogus: {version: engine.version, syncID: engine.syncID}}}},
+    steam: {}
+  });
+
+  await SyncTestingInfrastructure(server);
+  try {
+    let submitPromise = new Promise(resolve => {
+      telem.submit = function() {
+        let result = oldSubmit.apply(this, arguments);
+        resolve(result);
+      };
+    });
+    Service.sync();
+    let pingSubmitted = await submitPromise;
+    // The Sync testing infrastructure already sets up a custom token server,
+    // so we don't need to do anything to simulate a self-hosted user.
+    ok(!pingSubmitted, "Should not submit ping with custom token server URL");
+  } finally {
+    telem.submit = oldSubmit;
+    Service.engineManager.unregister(engine);
+    await cleanAndGo(engine, server);
+  }
+});