From daebd4816c330405a608efe6370a66c642c7ef21 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 24 May 2019 16:23:31 +0000 Subject: [PATCH] Bug 1554178 - Disable events sampling for uptake telemetry tests r=glasserc Differential Revision: https://phabricator.services.mozilla.com/D32484 --HG-- extra : moz-landing-system : lando --- services/common/tests/unit/head_helpers.js | 14 ++++ .../tests/unit/test_uptake_telemetry.js | 14 ---- .../test/unit/test_remote_settings.js | 16 ++-- .../test/unit/test_remote_settings_poll.js | 78 ++++++++++--------- 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/services/common/tests/unit/head_helpers.js b/services/common/tests/unit/head_helpers.js index 2efe9d5e5b35..2244c11211bc 100644 --- a/services/common/tests/unit/head_helpers.js +++ b/services/common/tests/unit/head_helpers.js @@ -198,3 +198,17 @@ function checkUptakeTelemetry(snapshot1, snapshot2, expectedIncrements) { equal(expected, actual, `check events for ${status}`); } } + +async function withFakeChannel(channel, f) { + const module = ChromeUtils.import("resource://services-common/uptake-telemetry.js", null); + const oldPolicy = module.Policy; + module.Policy = { + ...oldPolicy, + getChannel: () => channel, + }; + try { + return await f(); + } finally { + module.Policy = oldPolicy; + } +} diff --git a/services/common/tests/unit/test_uptake_telemetry.js b/services/common/tests/unit/test_uptake_telemetry.js index 7fc85cea67c8..1fcda5eceac6 100644 --- a/services/common/tests/unit/test_uptake_telemetry.js +++ b/services/common/tests/unit/test_uptake_telemetry.js @@ -20,20 +20,6 @@ async function withFakeClientID(uuid, f) { } } -async function withFakeChannel(channel, f) { - const module = ChromeUtils.import("resource://services-common/uptake-telemetry.js", null); - const oldPolicy = module.Policy; - module.Policy = { - ...oldPolicy, - getChannel: () => channel, - }; - try { - return await f(); - } finally { - module.Policy = oldPolicy; - } -} - add_task(async function test_unknown_status_is_not_reported() { const source = "update-source"; const startHistogram = getUptakeTelemetrySnapshot(source); diff --git a/services/settings/test/unit/test_remote_settings.js b/services/settings/test/unit/test_remote_settings.js index 7ed074ece972..09da3ffc291f 100644 --- a/services/settings/test/unit/test_remote_settings.js +++ b/services/settings/test/unit/test_remote_settings.js @@ -343,14 +343,16 @@ add_task(async function test_telemetry_if_sync_succeeds() { }); add_task(clear_state); -add_task(async function test_synchronization_duration_is_reported_in_uptake_status() { - await client.maybeSync(2000); +add_task( + withFakeChannel("nightly", /* test_synchronization_duration_is_reported_in_uptake_status */ async () => { + await client.maybeSync(2000); - TelemetryTestUtils.assertEvents([ - ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, - { source: client.identifier, duration: (v) => v > 0, trigger: "manual" }], - ]); -}); + TelemetryTestUtils.assertEvents([ + ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, + { source: client.identifier, duration: (v) => v > 0, trigger: "manual" }], + ]); + }) +); add_task(clear_state); add_task(async function test_telemetry_reports_if_application_fails() { diff --git a/services/settings/test/unit/test_remote_settings_poll.js b/services/settings/test/unit/test_remote_settings_poll.js index edd5d76f24cf..ff3f60bc10a2 100644 --- a/services/settings/test/unit/test_remote_settings_poll.js +++ b/services/settings/test/unit/test_remote_settings_poll.js @@ -302,49 +302,53 @@ add_task(async function test_client_last_check_is_saved() { add_task(clear_state); -add_task(async function test_age_of_data_is_reported_in_uptake_status() { - const serverTime = 1552323900000; - server.registerPathHandler(CHANGES_PATH, serveChangesEntries(serverTime, [{ - id: "b6ba7fab-a40a-4d03-a4af-6b627f3c5b36", - last_modified: serverTime - 3600 * 1000, - host: "localhost", - bucket: "main", - collection: "some-entry", - }])); +add_task( + withFakeChannel("nightly", /* test_age_of_data_is_reported_in_uptake_status */ async () => { + const serverTime = 1552323900000; + server.registerPathHandler(CHANGES_PATH, serveChangesEntries(serverTime, [{ + id: "b6ba7fab-a40a-4d03-a4af-6b627f3c5b36", + last_modified: serverTime - 3600 * 1000, + host: "localhost", + bucket: "main", + collection: "some-entry", + }])); - await RemoteSettings.pollChanges(); + await RemoteSettings.pollChanges(); - TelemetryTestUtils.assertEvents([ - ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, - { source: TELEMETRY_HISTOGRAM_POLL_KEY, age: "3600", trigger: "manual" }], - ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, - { source: TELEMETRY_HISTOGRAM_SYNC_KEY, duration: () => true, trigger: "manual" }], - ]); -}); + TelemetryTestUtils.assertEvents([ + ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, + { source: TELEMETRY_HISTOGRAM_POLL_KEY, age: "3600", trigger: "manual" }], + ["uptake.remotecontent.result", "uptake", "remotesettings", UptakeTelemetry.STATUS.SUCCESS, + { source: TELEMETRY_HISTOGRAM_SYNC_KEY, duration: () => true, trigger: "manual" }], + ]); + }) +); add_task(clear_state); -add_task(async function test_synchronization_duration_is_reported_in_uptake_status() { - server.registerPathHandler(CHANGES_PATH, serveChangesEntries(10000, [{ - id: "b6ba7fab-a40a-4d03-a4af-6b627f3c5b36", - last_modified: 42, - host: "localhost", - bucket: "main", - collection: "some-entry", - }])); - const c = RemoteSettings("some-entry"); - // Simulate a synchronization that lasts 1 sec. - // eslint-disable-next-line mozilla/no-arbitrary-setTimeout - c.maybeSync = () => new Promise(resolve => setTimeout(resolve, 1000)); +add_task( + withFakeChannel("nightly", /* test_synchronization_duration_is_reported_in_uptake_status */ async () => { + server.registerPathHandler(CHANGES_PATH, serveChangesEntries(10000, [{ + id: "b6ba7fab-a40a-4d03-a4af-6b627f3c5b36", + last_modified: 42, + host: "localhost", + bucket: "main", + collection: "some-entry", + }])); + const c = RemoteSettings("some-entry"); + // Simulate a synchronization that lasts 1 sec. + // eslint-disable-next-line mozilla/no-arbitrary-setTimeout + c.maybeSync = () => new Promise(resolve => setTimeout(resolve, 1000)); - await RemoteSettings.pollChanges(); + await RemoteSettings.pollChanges(); - TelemetryTestUtils.assertEvents([ - ["uptake.remotecontent.result", "uptake", "remotesettings", "success", - { source: TELEMETRY_HISTOGRAM_POLL_KEY, age: () => true, trigger: "manual" }], - ["uptake.remotecontent.result", "uptake", "remotesettings", "success", - { source: TELEMETRY_HISTOGRAM_SYNC_KEY, duration: (v) => v >= 1000, trigger: "manual" }], - ]); -}); + TelemetryTestUtils.assertEvents([ + ["uptake.remotecontent.result", "uptake", "remotesettings", "success", + { source: TELEMETRY_HISTOGRAM_POLL_KEY, age: () => true, trigger: "manual" }], + ["uptake.remotecontent.result", "uptake", "remotesettings", "success", + { source: TELEMETRY_HISTOGRAM_SYNC_KEY, duration: (v) => v >= 1000, trigger: "manual" }], + ]); + }) +); add_task(clear_state); add_task(async function test_success_with_partial_list() {