Bug 1348890 - Call setup()/shutdown() consistently r?gsvelto draft
authorAdam Gashlin <agashlin@mozilla.com>
Thu, 07 Dec 2017 15:29:35 -0800
changeset 709310 c15e6d08b42f2ebe7ddce29cbd640345c52370c3
parent 709018 e30c06a1074c2455f47e0bafb9bb84ec1a09d682
child 743394 c1d1fdf2b40f055a4f2aeda35cd11d9e70b2bb9f
push id92614
push userbmo:agashlin@mozilla.com
push dateThu, 07 Dec 2017 23:31:48 +0000
reviewersgsvelto
bugs1348890
milestone59.0a1
Bug 1348890 - Call setup()/shutdown() consistently r?gsvelto MozReview-Commit-ID: KShqEuf5xT7
toolkit/components/telemetry/TelemetrySend.jsm
toolkit/components/telemetry/tests/unit/head.js
toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -207,16 +207,25 @@ this.TelemetrySend = {
    *
    * @return {Promise} Promise that is resolved when shutdown is finished.
    */
   shutdown() {
     return TelemetrySendImpl.shutdown();
   },
 
   /**
+   * Used only for testing purposes
+   *
+   * @return {Boolean} true if the module has been setup and not shutdown
+   */
+  shouldShutdown() {
+    return TelemetrySendImpl.shouldShutdown();
+  },
+
+  /**
    * Submit a ping for sending. This will:
    * - send the ping right away if possible or
    * - save the ping to disk and send it at the next opportunity
    *
    * @param {Object} ping The ping data to send, must be serializable to JSON.
    * @param {Object} [aOptions] Options object.
    * @param {Boolean} [options.usePingSender=false] if true, send the ping using the PingSender.
    * @return {Promise} Test-only - a promise that is resolved when the ping is sent or saved.
@@ -804,16 +813,20 @@ var TelemetrySendImpl = {
     // Let the scheduler trigger sending pings if possible, also inform the
     // crash reporter that it can send crash pings if appropriate.
     SendScheduler.triggerSendingPings(true);
     this._annotateCrashReport();
 
     return this.promisePendingPingActivity();
   },
 
+  shouldShutdown() {
+    return this._sendingEnabled && !this._shutdown;
+  },
+
   observe(subject, topic, data) {
     let setOSShutdown = () => {
       this._log.trace("setOSShutdown - in OS shutdown");
       this._isOSShutdown = true;
     };
 
     switch (topic) {
     case TOPIC_IDLE_DAILY:
--- a/toolkit/components/telemetry/tests/unit/head.js
+++ b/toolkit/components/telemetry/tests/unit/head.js
@@ -354,17 +354,21 @@ if (runningInParent) {
 
   fakePingSendTimer((callback, timeout) => {
     Services.tm.dispatchToMainThread(() => callback());
   },
   () => {});
 
   // This gets imported via fakeNow();
   /* global TelemetrySend */
-  do_register_cleanup(() => TelemetrySend.shutdown());
+  do_register_cleanup(() => {
+    if (TelemetrySend.shouldShutdown()) {
+      TelemetrySend.shutdown();
+    }
+  });
 }
 
 TelemetryController.testInitLogging();
 
 // Avoid timers interrupting test behavior.
 fakeSchedulerTimer(() => {}, () => {});
 // Make pind sending predictable.
 fakeMidnightPingFuzzingDelay(0);
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -457,16 +457,17 @@ add_task(async function test_persistCurr
   await TelemetrySend.reset();
   Assert.equal(TelemetrySend.pendingPingCount, PING_COUNT, "Should have the correct pending ping count");
 });
 
 add_task(async function test_sendCheckOverride() {
   const TEST_PING_TYPE = "test-sendCheckOverride";
 
   // Clear any pending pings.
+  await TelemetryController.testSetup();
   await TelemetryController.testShutdown();
   await TelemetryStorage.testClearPendingPings();
 
   // Enable the ping server.
   PingServer.start();
   Services.prefs.setStringPref(TelemetryUtils.Preferences.Server, "http://localhost:" + PingServer.port);
 
   // Start Telemetry and disable the test-mode so pings don't get