Bug 1348890 - Call setup()/shutdown() consistently r?gsvelto
MozReview-Commit-ID: KShqEuf5xT7
--- 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