Bug 1385417 - Fix sendOnTimeout test. r=gfritzsche
☠☠ backed out by 6e7e4865a477 ☠ ☠
authorKate Ustiuzhanina <kustiuzhanina@mozilla.com>
Mon, 31 Jul 2017 14:57:33 +0100
changeset 420835 4446ecfee3d7530ae423be58cd0c34f054564d8a
parent 420834 2bb82c799d1a6cca273d59401eb06842b9ed0ea1
child 420836 77c33119b5ca241a70b58744b70d3f5ebe5ca72d
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1385417
milestone56.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 1385417 - Fix sendOnTimeout test. r=gfritzsche
toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js
@@ -6,16 +6,17 @@
 
 "use strict";
 
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+Cu.import("resource://testing-common/TelemetryArchiveTesting.jsm", this);
 
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryHealthPing",
                                   "resource://gre/modules/TelemetryHealthPing.jsm");
 
 function checkHealthPingStructure(ping, expectedFailuresDict) {
   let payload = ping.payload;
   Assert.equal(ping.type, TelemetryHealthPing.HEALTH_PING_TYPE, "Should have recorded a health ping.");
 
@@ -25,16 +26,28 @@ function checkHealthPingStructure(ping, 
 }
 
 function fakeHealthSchedulerTimer(set, clear) {
   let telemetryHealthPing = Cu.import("resource://gre/modules/TelemetryHealthPing.jsm", {});
   telemetryHealthPing.Policy.setSchedulerTickTimeout = set;
   telemetryHealthPing.Policy.clearSchedulerTickTimeout = clear;
 }
 
+async function waitForConditionWithPromise(promiseFn, timeoutMsg, tryCount = 30) {
+  const SINGLE_TRY_TIMEOUT = 100;
+  let tries = 0;
+  do {
+    try {
+      return await promiseFn();
+    } catch (ex) {}
+    await new Promise(resolve => do_timeout(SINGLE_TRY_TIMEOUT, resolve));
+  } while (++tries <= tryCount);
+  throw new Error(timeoutMsg);
+}
+
 add_task(async function setup() {
   // Trigger a proper telemetry init.
   do_get_profile(true);
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
   Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
   Preferences.set(TelemetryUtils.Preferences.HealthPingEnabled, true);
 
@@ -111,23 +124,33 @@ add_task(async function test_sendOverSiz
 add_task(async function test_sendOnTimeout() {
   TelemetryHealthPing.testReset();
   PingServer.clearRequests();
   let PING_TYPE = "ping-on-timeout";
 
   // Set up small ping submission timeout to always have timeout error.
   TelemetrySend.testSetTimeoutForPingSubmit(2);
 
-  // Reset the timeout after receiving the first ping to be able to send health ping.
   PingServer.registerPingHandler((request, result) => {
     PingServer.resetPingHandler();
-    TelemetrySend.testResetTimeOutToDefault();
   });
 
+  // Submit a ping which should time out.
   await TelemetryController.submitExternalPing(PING_TYPE, {});
+
+  let ac = new TelemetryArchiveTesting.Checker();
+  await ac.promiseInit();
+  await waitForConditionWithPromise(() => {
+    ac.promiseFindPing("health", []);
+  }, "Failed to find health ping");
+
+  TelemetrySend.testResetTimeOutToDefault();
+  PingServer.resetPingHandler();
+  TelemetryController.submitExternalPing(PING_TYPE, {});
+
   let ping = await PingServer.promiseNextPing();
   checkHealthPingStructure(ping, {
     [TelemetryHealthPing.FailureType.SEND_FAILURE]: {
       "timeout": 1
     },
     "os": TelemetryHealthPing.OsInfo,
     "reason": TelemetryHealthPing.Reason.IMMEDIATE
   });