mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 1145188: Shifting TelemetrySession init control to TelemetryController (test). r=Dexter
This commit is contained in:
parent
af97a1b2ef
commit
c1c4ebbd1d
@ -6,7 +6,6 @@
|
||||
|
||||
Cu.import("resource:///modules/experiments/Experiments.jsm");
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
|
||||
const FILE_MANIFEST = "experiments.manifest";
|
||||
const SEC_IN_ONE_DAY = 24 * 60 * 60;
|
||||
@ -53,8 +52,7 @@ add_task(function* test_setup() {
|
||||
createAppInfo();
|
||||
gProfileDir = do_get_profile();
|
||||
startAddonManagerOnly();
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
gPolicy = new Experiments.Policy();
|
||||
|
||||
patchPolicy(gPolicy, {
|
||||
@ -329,5 +327,5 @@ add_task(function* test_times() {
|
||||
});
|
||||
|
||||
add_task(function* test_shutdown() {
|
||||
yield TelemetrySession.shutdown(false);
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
@ -299,7 +299,7 @@ if (runningInParent) {
|
||||
do_register_cleanup(() => TelemetrySend.shutdown());
|
||||
}
|
||||
|
||||
TelemetryController.initLogging();
|
||||
TelemetryController.testInitLogging();
|
||||
|
||||
// Avoid timers interrupting test behavior.
|
||||
fakeSchedulerTimer(() => {}, () => {});
|
||||
|
@ -57,8 +57,7 @@ function check_histogram_values(payload) {
|
||||
|
||||
add_task(function*() {
|
||||
if (!runningInParent) {
|
||||
TelemetryController.setupContent();
|
||||
TelemetrySession.setupContent();
|
||||
TelemetryController.testSetupContent();
|
||||
run_child_test();
|
||||
dump("... done with child test\n");
|
||||
do_send_remote_message(MESSAGE_CHILD_TEST_DONE);
|
||||
@ -71,8 +70,7 @@ add_task(function*() {
|
||||
do_get_profile(true);
|
||||
loadAddonManager(APP_ID, APP_NAME, APP_VERSION, PLATFORM_VERSION);
|
||||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
|
||||
// Run test in child, don't wait for it to finish.
|
||||
let childPromise = run_test_in_child("test_ChildHistograms.js");
|
||||
|
@ -7,9 +7,7 @@
|
||||
"use strict";
|
||||
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetryArchive.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
||||
Cu.import("resource://gre/modules/osfile.jsm", this);
|
||||
Cu.import("resource://gre/modules/Task.jsm", this);
|
||||
@ -120,7 +118,7 @@ add_task(function* test_archivedPings() {
|
||||
yield checkLoadingPings();
|
||||
|
||||
// Check that we find the archived pings again by scanning after a restart.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
let pingList = yield TelemetryArchive.promiseArchivedPingList();
|
||||
Assert.deepEqual(expectedPingList, pingList,
|
||||
@ -174,7 +172,7 @@ add_task(function* test_archivedPings() {
|
||||
expectedPingList.sort((a, b) => a.timestampCreated - b.timestampCreated);
|
||||
|
||||
// Reset the TelemetryArchive so we scan the archived dir again.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Check that we are still picking up the valid archived pings on disk,
|
||||
// plus the valid ones above.
|
||||
@ -202,7 +200,7 @@ add_task(function* test_archiveCleanup() {
|
||||
Telemetry.getHistogramById("TELEMETRY_DISCARDED_ARCHIVED_PINGS_SIZE_MB").clear();
|
||||
|
||||
// Build the cache. Nothing should be evicted as there's no ping directory.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
yield TelemetryArchive.promiseArchivedPingList();
|
||||
|
||||
@ -264,7 +262,7 @@ add_task(function* test_archiveCleanup() {
|
||||
// Move the current date 180 days ahead of the first ping.
|
||||
let now = fakeNow(2010, 7, 1, 1, 0, 0);
|
||||
// Reset TelemetryArchive and TelemetryController to start the startup cleanup.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
// Wait for the cleanup to finish.
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
// Then scan the archived dir.
|
||||
@ -297,7 +295,7 @@ add_task(function* test_archiveCleanup() {
|
||||
// Move the current date 180 days ahead of the second ping.
|
||||
fakeNow(2010, 8, 1, 1, 0, 0);
|
||||
// Reset TelemetryController and TelemetryArchive.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
// Wait for the cleanup to finish.
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
// Then scan the archived dir again.
|
||||
@ -346,7 +344,7 @@ add_task(function* test_archiveCleanup() {
|
||||
expectedPrunedInfo = expectedPrunedInfo.concat(pingsOutsideQuota);
|
||||
|
||||
// Reset TelemetryArchive and TelemetryController to start the startup cleanup.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
yield TelemetryArchive.promiseArchivedPingList();
|
||||
// Check that the archive is in the correct state.
|
||||
@ -359,7 +357,7 @@ add_task(function* test_archiveCleanup() {
|
||||
Assert.equal(h.sum, 300, "Archive quota was hit, a special size must be reported.");
|
||||
|
||||
// Trigger a cleanup again and make sure we're not removing anything.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
yield TelemetryArchive.promiseArchivedPingList();
|
||||
yield checkArchive();
|
||||
@ -384,7 +382,7 @@ add_task(function* test_archiveCleanup() {
|
||||
expectedPrunedInfo.push({ id: OVERSIZED_PING_ID, creationDate: new Date(OVERSIZED_PING.creationDate) });
|
||||
|
||||
// Scan the archive.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testCleanupTaskPromise();
|
||||
yield TelemetryArchive.promiseArchivedPingList();
|
||||
// The following also checks that non oversized pings are not removed.
|
||||
@ -401,7 +399,7 @@ add_task(function* test_archiveCleanup() {
|
||||
add_task(function* test_clientId() {
|
||||
// Check that a ping submitted after the delayed telemetry initialization completed
|
||||
// should get a valid client id.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
const clientId = TelemetryController.clientID;
|
||||
|
||||
let id = yield TelemetryController.submitExternalPing("test-type", {}, {addClientId: true});
|
||||
@ -415,7 +413,7 @@ add_task(function* test_clientId() {
|
||||
// We should have cached the client id now. Lets confirm that by
|
||||
// checking the client id on a ping submitted before the async
|
||||
// controller setup is finished.
|
||||
let promiseSetup = TelemetryController.reset();
|
||||
let promiseSetup = TelemetryController.testReset();
|
||||
id = yield TelemetryController.submitExternalPing("test-type", {}, {addClientId: true});
|
||||
ping = yield TelemetryArchive.promiseArchivedPingById(id);
|
||||
Assert.equal(ping.clientId, clientId);
|
||||
@ -448,7 +446,7 @@ add_task(function* test_InvalidPingType() {
|
||||
});
|
||||
|
||||
add_task(function* test_currentPingData() {
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
|
||||
// Setup test data.
|
||||
let h = Telemetry.getHistogramById("TELEMETRY_TEST_RELEASE_OPTOUT");
|
||||
@ -477,5 +475,5 @@ add_task(function* test_currentPingData() {
|
||||
});
|
||||
|
||||
add_task(function* test_shutdown() {
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
@ -122,16 +122,16 @@ add_task(function* test_subsessionsChaining() {
|
||||
|
||||
// Start and shut down Telemetry. We expect a shutdown ping with profileSubsessionCounter: 1,
|
||||
// subsessionCounter: 1, subsessionId: A, and previousSubsessionId: null to be archived.
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testSetup();
|
||||
yield TelemetryController.testShutdown();
|
||||
expectedReasons.push(REASON_SHUTDOWN);
|
||||
|
||||
// Start Telemetry but don't wait for it to initialise before shutting down. We expect a
|
||||
// shutdown ping with profileSubsessionCounter: 2, subsessionCounter: 1, subsessionId: B
|
||||
// and previousSubsessionId: A to be archived.
|
||||
moveClockForward(30);
|
||||
TelemetrySession.reset();
|
||||
yield TelemetrySession.shutdown();
|
||||
TelemetryController.testReset();
|
||||
yield TelemetryController.testShutdown();
|
||||
expectedReasons.push(REASON_SHUTDOWN);
|
||||
|
||||
// Start Telemetry and simulate an aborted-session ping. We expect an aborted-session ping
|
||||
@ -139,11 +139,11 @@ add_task(function* test_subsessionsChaining() {
|
||||
// previousSubsessionId: B to be archived.
|
||||
let schedulerTickCallback = null;
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
moveClockForward(6);
|
||||
// Trigger the an aborted session ping save. When testing,we are not saving the aborted-session
|
||||
// ping as soon as Telemetry starts, otherwise we would end up with unexpected pings being
|
||||
// sent when calling |TelemetrySession.reset()|, thus breaking some tests.
|
||||
// sent when calling |TelemetryController.testReset()|, thus breaking some tests.
|
||||
Assert.ok(!!schedulerTickCallback);
|
||||
yield schedulerTickCallback();
|
||||
expectedReasons.push(REASON_ABORTED_SESSION);
|
||||
@ -152,9 +152,8 @@ add_task(function* test_subsessionsChaining() {
|
||||
// an environment-change ping with profileSubsessionCounter: 4, subsessionCounter: 1,
|
||||
// subsessionId: D and previousSubsessionId: C to be archived.
|
||||
moveClockForward(30);
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetrySession.reset();
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
yield TelemetryController.testReset();
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
moveClockForward(30);
|
||||
Preferences.set(PREF_TEST, 1);
|
||||
expectedReasons.push(REASON_ENVIRONMENT_CHANGE);
|
||||
@ -162,14 +161,14 @@ add_task(function* test_subsessionsChaining() {
|
||||
// Shut down Telemetry. We expect a shutdown ping with profileSubsessionCounter: 5,
|
||||
// subsessionCounter: 2, subsessionId: E and previousSubsessionId: D to be archived.
|
||||
moveClockForward(30);
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
expectedReasons.push(REASON_SHUTDOWN);
|
||||
|
||||
// Start Telemetry and trigger a daily ping. We expect a daily ping with
|
||||
// profileSubsessionCounter: 6, subsessionCounter: 1, subsessionId: F and
|
||||
// previousSubsessionId: E to be archived.
|
||||
moveClockForward(30);
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Delay the callback around midnight.
|
||||
now = fakeNow(futureDate(now, MS_IN_ONE_DAY));
|
||||
@ -186,12 +185,12 @@ add_task(function* test_subsessionsChaining() {
|
||||
|
||||
// Shut down Telemetry and trigger a shutdown ping.
|
||||
moveClockForward(30);
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
expectedReasons.push(REASON_SHUTDOWN);
|
||||
|
||||
// Start Telemetry and trigger an environment change.
|
||||
yield TelemetrySession.reset();
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
yield TelemetryController.testReset();
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
moveClockForward(30);
|
||||
Preferences.set(PREF_TEST, 1);
|
||||
expectedReasons.push(REASON_ENVIRONMENT_CHANGE);
|
||||
@ -204,8 +203,7 @@ add_task(function* test_subsessionsChaining() {
|
||||
|
||||
// Start Telemetry and trigger a daily ping.
|
||||
moveClockForward(30);
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
// Delay the callback around midnight.
|
||||
now = futureDate(now, MS_IN_ONE_DAY);
|
||||
fakeNow(now);
|
||||
@ -225,13 +223,12 @@ add_task(function* test_subsessionsChaining() {
|
||||
expectedReasons.push(REASON_ABORTED_SESSION);
|
||||
|
||||
// Make sure the aborted-session ping gets archived.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
yield promiseValidateArchivedPings(expectedReasons);
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
do_test_finished();
|
||||
});
|
||||
|
@ -104,13 +104,13 @@ function run_test() {
|
||||
}
|
||||
|
||||
add_task(function* asyncSetup() {
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
|
||||
gClientID = yield ClientID.getClientID();
|
||||
|
||||
// We should have cached the client id now. Lets confirm that by
|
||||
// checking the client id before the async ping setup is finished.
|
||||
let promisePingSetup = TelemetryController.reset();
|
||||
let promisePingSetup = TelemetryController.testReset();
|
||||
do_check_eq(TelemetryController.clientID, gClientID);
|
||||
yield promisePingSetup;
|
||||
});
|
||||
@ -171,13 +171,13 @@ add_task(function* test_disableDataUpload() {
|
||||
// Disable FHR upload to send a deletion ping again.
|
||||
Preferences.set(PREF_FHR_UPLOAD_ENABLED, false);
|
||||
|
||||
// Wait on sending activity to settle, as |TelemetryController.reset()| doesn't do that.
|
||||
// Wait on sending activity to settle, as |TelemetryController.testReset()| doesn't do that.
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
// Wait for the pending pings to be deleted. Resetting TelemetryController doesn't
|
||||
// trigger the shutdown, so we need to call it ourselves.
|
||||
yield TelemetryStorage.shutdown();
|
||||
// Simulate a restart, and spin the send task.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Disabling Telemetry upload must clear out all the pending pings.
|
||||
let pendingPings = yield TelemetryStorage.loadPendingPingList();
|
||||
@ -187,11 +187,11 @@ add_task(function* test_disableDataUpload() {
|
||||
// Enable the ping server again.
|
||||
PingServer.start();
|
||||
// We set the new server using the pref, otherwise it would get reset with
|
||||
// |TelemetryController.reset|.
|
||||
// |TelemetryController.testReset|.
|
||||
Preferences.set(PREF_TELEMETRY_SERVER, "http://localhost:" + PingServer.port);
|
||||
|
||||
// Reset the controller to spin the ping sending task.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
ping = yield PingServer.promiseNextPing();
|
||||
checkPingFormat(ping, DELETION_PING_TYPE, true, false);
|
||||
|
||||
@ -301,7 +301,7 @@ add_task(function* test_midnightPingSendFuzzing() {
|
||||
});
|
||||
|
||||
PingServer.clearRequests();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// A ping after midnight within the fuzzing delay should not get sent.
|
||||
now = new Date(2030, 5, 2, 0, 40, 0);
|
||||
@ -382,7 +382,7 @@ add_task(function* test_telemetryEnabledUnexpectedValue(){
|
||||
// Set the preferences controlling the Telemetry status to a string.
|
||||
Preferences.set(PREF_ENABLED, "false");
|
||||
// Check that Telemetry is not enabled.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
Assert.equal(Telemetry.canRecordExtended, false,
|
||||
"Invalid values must not enable Telemetry recording.");
|
||||
|
||||
@ -391,13 +391,13 @@ add_task(function* test_telemetryEnabledUnexpectedValue(){
|
||||
|
||||
// Make sure that flipping it to true works.
|
||||
Preferences.set(PREF_ENABLED, true);
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
Assert.equal(Telemetry.canRecordExtended, true,
|
||||
"True must enable Telemetry recording.");
|
||||
|
||||
// Also check that the false works as well.
|
||||
Preferences.set(PREF_ENABLED, false);
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
Assert.equal(Telemetry.canRecordExtended, false,
|
||||
"False must disable Telemetry recording.");
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
// Force the Telemetry enabled preference so that TelemetrySession.reset() doesn't exit early.
|
||||
// Force the Telemetry enabled preference so that TelemetrySession.testReset() doesn't exit early.
|
||||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
|
||||
// Set up our dummy AppInfo object so we can control the appBuildID.
|
||||
@ -30,7 +30,7 @@ updateAppInfo();
|
||||
// Check that when run with no previous build ID stored, we update the pref but do not
|
||||
// put anything into the metadata.
|
||||
add_task(function* test_firstRun() {
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
let metadata = TelemetrySession.getMetadata();
|
||||
do_check_false("previousBuildID" in metadata);
|
||||
let appBuildID = getAppInfo().appBuildID;
|
||||
@ -41,7 +41,7 @@ add_task(function* test_firstRun() {
|
||||
// Check that a subsequent run with the same build ID does not put prev build ID in
|
||||
// metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref.
|
||||
add_task(function* test_secondRun() {
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
let metadata = TelemetrySession.getMetadata();
|
||||
do_check_false("previousBuildID" in metadata);
|
||||
});
|
||||
@ -54,7 +54,7 @@ add_task(function* test_newBuild() {
|
||||
let info = getAppInfo();
|
||||
let oldBuildID = info.appBuildID;
|
||||
info.appBuildID = NEW_BUILD_ID;
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
let metadata = TelemetrySession.getMetadata();
|
||||
do_check_eq(metadata.previousBuildId, oldBuildID);
|
||||
let buildIDPref = Services.prefs.getCharPref(TelemetrySession.Constants.PREF_PREVIOUS_BUILDID);
|
||||
|
@ -37,18 +37,25 @@ function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* test_sendTimeout() {
|
||||
const TIMEOUT = 100;
|
||||
/**
|
||||
* Ensures that TelemetryController does not hang processing shutdown
|
||||
* phases. Assumes that Telemetry shutdown routines do not take longer than
|
||||
* CRASH_TIMEOUT_MS to complete.
|
||||
*/
|
||||
add_task(function* test_sendTelemetryShutsDownWithinReasonableTimeout() {
|
||||
const CRASH_TIMEOUT_MS = 5 * 1000;
|
||||
// Enable testing mode for AsyncShutdown, otherwise some testing-only functionality
|
||||
// is not available.
|
||||
Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
|
||||
Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", TIMEOUT);
|
||||
// Reducing the max delay for waitiing on phases to complete from 1 minute
|
||||
// (standard) to 10 seconds to avoid blocking the tests in case of misbehavior.
|
||||
Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", CRASH_TIMEOUT_MS);
|
||||
|
||||
let httpServer = new HttpServer();
|
||||
httpServer.registerPrefixHandler("/", contentHandler);
|
||||
httpServer.start(-1);
|
||||
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
TelemetrySend.setServer("http://localhost:" + httpServer.identity.primaryPort);
|
||||
let submissionPromise = TelemetryController.submitExternalPing("test-ping-type", {});
|
||||
|
||||
|
@ -42,7 +42,7 @@ add_task(function* testSendPendingOnIdleDaily() {
|
||||
yield TelemetryStorage.savePing(PENDING_PING, true);
|
||||
|
||||
// Telemetry will not send this ping at startup, because it's not overdue.
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
TelemetrySend.setServer("http://localhost:" + gHttpServer.identity.primaryPort);
|
||||
|
||||
let pendingPromise = new Promise(resolve =>
|
||||
|
@ -814,7 +814,7 @@ add_task(function* test_prefWatchPolicies() {
|
||||
Preferences.set(PREF_TEST_5, expectedValue);
|
||||
|
||||
// Set the Environment preferences to watch.
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
let deferred = PromiseUtils.defer();
|
||||
|
||||
// Check that the pref values are missing or present as expected
|
||||
@ -862,7 +862,7 @@ add_task(function* test_prefWatch_prefReset() {
|
||||
fakeNow(gNow);
|
||||
|
||||
// Set the Environment preferences to watch.
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
let deferred = PromiseUtils.defer();
|
||||
TelemetryEnvironment.registerChangeListener("testWatchPrefs_reset", deferred.resolve);
|
||||
|
||||
@ -1290,7 +1290,7 @@ add_task(function* test_changeThrottling() {
|
||||
fakeNow(gNow);
|
||||
|
||||
// Set the Environment preferences to watch.
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
let deferred = PromiseUtils.defer();
|
||||
let changeCount = 0;
|
||||
TelemetryEnvironment.registerChangeListener("testWatchPrefs_throttling", () => {
|
||||
@ -1448,7 +1448,7 @@ add_task(function* test_defaultSearchEngine() {
|
||||
// Set the clock in the future so our changes don't get throttled.
|
||||
gNow = fakeNow(futureDate(gNow, 10 * MILLISECONDS_PER_MINUTE));
|
||||
// Watch the test preference.
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
deferred = PromiseUtils.defer();
|
||||
TelemetryEnvironment.registerChangeListener("testSearchEngine_pref", deferred.resolve);
|
||||
// Trigger an environment change.
|
||||
@ -1482,7 +1482,7 @@ add_task(function* test_environmentShutdown() {
|
||||
fakeNow(gNow);
|
||||
|
||||
// Set up the preferences and listener, then the trigger shutdown
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.registerChangeListener("test_environmentShutdownChange", () => {
|
||||
// Register a new change listener that asserts if change is propogated
|
||||
Assert.ok(false, "No change should be propagated after shutdown.");
|
||||
|
@ -27,7 +27,9 @@ function check_event(event, id, data)
|
||||
add_task(function* ()
|
||||
{
|
||||
do_get_profile();
|
||||
yield TelemetrySession.setup();
|
||||
// TODO: After Bug 1254550 lands we should not need to set the pref here.
|
||||
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
|
||||
yield TelemetryController.testSetup();
|
||||
|
||||
TelemetryLog.log(TEST_PREFIX + "1", ["val", 123, undefined]);
|
||||
TelemetryLog.log(TEST_PREFIX + "2", []);
|
||||
@ -45,5 +47,5 @@ add_task(function* ()
|
||||
do_check_true(log[0][1] <= log[1][1]);
|
||||
do_check_true(log[1][1] <= log[2][1]);
|
||||
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
@ -217,7 +217,7 @@ add_task(function* test_canSend() {
|
||||
PingServer.start();
|
||||
Preferences.set(PREF_SERVER, "http://localhost:" + PingServer.port);
|
||||
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
TelemetryReportingPolicy.reset();
|
||||
|
||||
// User should be reported as not notified by default.
|
||||
@ -248,7 +248,7 @@ add_task(function* test_canSend() {
|
||||
|
||||
// Fake a restart with a pending ping.
|
||||
yield TelemetryController.addPendingPing(TEST_PING_TYPE, {});
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// We should be immediately sending the ping out.
|
||||
ping = yield PingServer.promiseNextPings(1);
|
||||
|
@ -120,7 +120,7 @@ add_task(function* test_sendPendingPings() {
|
||||
Preferences.set(PREF_TELEMETRY_SERVER, "http://localhost:" + PingServer.port);
|
||||
|
||||
let timerPromise = waitForTimer();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
let [pingSendTimerCallback, pingSendTimeout] = yield timerPromise;
|
||||
Assert.ok(!!pingSendTimerCallback, "Should have a timer callback");
|
||||
|
||||
|
@ -174,7 +174,7 @@ add_task(function* setupEnvironment() {
|
||||
// The following tests assume this pref to be true by default.
|
||||
Services.prefs.setBoolPref(PREF_FHR_UPLOAD, true);
|
||||
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
|
||||
let directory = TelemetryStorage.pingDirectoryPath;
|
||||
yield File.makeDir(directory, { ignoreExisting: true, unixMode: OS.Constants.S_IRWXU });
|
||||
@ -189,7 +189,7 @@ add_task(function* test_recent_pings_sent() {
|
||||
let pingTypes = [{ num: RECENT_PINGS }];
|
||||
let recentPings = yield createSavedPings(pingTypes);
|
||||
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
assertReceivedPings(RECENT_PINGS);
|
||||
|
||||
@ -255,7 +255,7 @@ add_task(function* test_overdue_old_format() {
|
||||
}
|
||||
|
||||
gSeenPings = 0;
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
assertReceivedPings(OLD_FORMAT_PINGS);
|
||||
|
||||
@ -329,7 +329,7 @@ add_task(function* test_overdue_pings_trigger_send() {
|
||||
let recentPings = pings.slice(0, RECENT_PINGS);
|
||||
let overduePings = pings.slice(-OVERDUE_PINGS);
|
||||
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
assertReceivedPings(TOTAL_EXPECTED_PINGS);
|
||||
|
||||
@ -385,7 +385,7 @@ add_task(function* test_overdue_old_format() {
|
||||
receivedPings++;
|
||||
});
|
||||
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
Assert.equal(receivedPings, 1, "We must receive a ping in the old format.");
|
||||
|
||||
@ -402,7 +402,7 @@ add_task(function* test_pendingPingsQuota() {
|
||||
// Remove all the pending pings then startup and wait for the cleanup task to complete.
|
||||
// There should be nothing to remove.
|
||||
yield clearPendingPings();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetrySend.testWaitOnOutgoingPings();
|
||||
yield TelemetryStorage.testPendingQuotaTaskPromise();
|
||||
|
||||
@ -455,7 +455,7 @@ add_task(function* test_pendingPingsQuota() {
|
||||
Telemetry.getHistogramById("TELEMETRY_PENDING_PINGS_EVICTED_OVER_QUOTA").clear();
|
||||
Telemetry.getHistogramById("TELEMETRY_PENDING_EVICTING_OVER_QUOTA_MS").clear();
|
||||
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testPendingQuotaTaskPromise();
|
||||
|
||||
// Check that the correct values for quota probes are reported when no quota is hit.
|
||||
@ -491,7 +491,7 @@ add_task(function* test_pendingPingsQuota() {
|
||||
expectedPrunedPings = pingsOutsideQuota;
|
||||
|
||||
// Reset TelemetryController to start the pending pings cleanup.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testPendingQuotaTaskPromise();
|
||||
yield checkPendingPings();
|
||||
|
||||
@ -502,7 +502,7 @@ add_task(function* test_pendingPingsQuota() {
|
||||
Assert.equal(h.sum, 17, "Pending pings quota was hit, a special size must be reported.");
|
||||
|
||||
// Trigger a cleanup again and make sure we're not removing anything.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testPendingQuotaTaskPromise();
|
||||
yield checkPendingPings();
|
||||
|
||||
@ -538,7 +538,7 @@ add_task(function* test_pendingPingsQuota() {
|
||||
expectedPrunedPings.push(OVERSIZED_PING_ID);
|
||||
|
||||
// Scan the pending pings directory.
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield TelemetryStorage.testPendingQuotaTaskPromise();
|
||||
yield checkPendingPings();
|
||||
|
||||
|
@ -455,8 +455,7 @@ function run_test() {
|
||||
}
|
||||
|
||||
add_task(function* asyncSetup() {
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
// Load the client ID from the client ID provider to check for pings sanity.
|
||||
gClientID = yield ClientID.getClientID();
|
||||
});
|
||||
@ -484,7 +483,6 @@ add_task(function* test_noServerPing() {
|
||||
// Checks that a sent ping is correctly received by a dummy http server.
|
||||
add_task(function* test_simplePing() {
|
||||
yield clearPendingPings();
|
||||
yield TelemetrySend.reset();
|
||||
PingServer.start();
|
||||
Preferences.set(PREF_SERVER, "http://localhost:" + PingServer.port);
|
||||
|
||||
@ -496,7 +494,7 @@ add_task(function* test_simplePing() {
|
||||
const expectedSessionUUID = "bd314d15-95bf-4356-b682-b6c4a8942202";
|
||||
const expectedSubsessionUUID = "3e2e5f6c-74ba-4e4d-a93f-a48af238a8c7";
|
||||
fakeGenerateUUID(() => expectedSessionUUID, () => expectedSubsessionUUID);
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Session and subsession start dates are faked during TelemetrySession setup. We can
|
||||
// now fake the session duration.
|
||||
@ -529,7 +527,7 @@ add_task(function* test_simplePing() {
|
||||
add_task(function* test_saveLoadPing() {
|
||||
// Let's start out with a defined state.
|
||||
yield clearPendingPings();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
PingServer.clearRequests();
|
||||
|
||||
// Setup test data and trigger pings.
|
||||
@ -569,7 +567,7 @@ add_task(function* test_checkSubsessionHistograms() {
|
||||
let now = new Date(2020, 1, 1, 12, 0, 0);
|
||||
let expectedDate = new Date(2020, 1, 1, 0, 0, 0);
|
||||
fakeNow(now);
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
const COUNT_ID = "TELEMETRY_TEST_COUNT";
|
||||
const KEYED_ID = "TELEMETRY_TEST_KEYED_COUNT";
|
||||
@ -760,7 +758,7 @@ add_task(function* test_checkSubsessionData() {
|
||||
++expectedActiveTicks;
|
||||
}
|
||||
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Both classic and subsession payload data should be the same on the first subsession.
|
||||
incrementActiveTicks();
|
||||
@ -811,7 +809,7 @@ add_task(function* test_dailyCollection() {
|
||||
|
||||
// Init and check timer.
|
||||
yield clearPendingPings();
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testSetup();
|
||||
TelemetrySend.setServer("http://localhost:" + PingServer.port);
|
||||
|
||||
// Set histograms to expected state.
|
||||
@ -892,7 +890,7 @@ add_task(function* test_dailyCollection() {
|
||||
Assert.equal(ping.payload.keyedHistograms[KEYED_ID]["b"].sum, 1);
|
||||
|
||||
// Shutdown to cleanup the aborted-session if it gets created.
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_dailyDuplication() {
|
||||
@ -910,7 +908,7 @@ add_task(function* test_dailyDuplication() {
|
||||
fakeNow(now);
|
||||
// Fake scheduler functions to control daily collection flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Make sure the daily ping gets triggered at midnight.
|
||||
// We need to make sure that we trigger this after the period where we wait for
|
||||
@ -946,7 +944,7 @@ add_task(function* test_dailyDuplication() {
|
||||
|
||||
// Shutdown to cleanup the aborted-session if it gets created.
|
||||
PingServer.resetPingHandler();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_dailyOverdue() {
|
||||
@ -960,7 +958,8 @@ add_task(function* test_dailyOverdue() {
|
||||
fakeNow(now);
|
||||
// Fake scheduler functions to control daily collection flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.setup();
|
||||
yield clearPendingPings();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Skip one hour ahead: nothing should be due.
|
||||
now.setHours(now.getHours() + 1);
|
||||
@ -996,7 +995,7 @@ add_task(function* test_dailyOverdue() {
|
||||
Assert.equal(ping.payload.info.reason, REASON_DAILY);
|
||||
|
||||
// Shutdown to cleanup the aborted-session if it gets created.
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_environmentChange() {
|
||||
@ -1010,7 +1009,6 @@ add_task(function* test_environmentChange() {
|
||||
let timerDelay = null;
|
||||
|
||||
yield clearPendingPings();
|
||||
yield TelemetrySend.reset();
|
||||
PingServer.clearRequests();
|
||||
|
||||
fakeNow(now);
|
||||
@ -1023,9 +1021,9 @@ add_task(function* test_environmentChange() {
|
||||
]);
|
||||
|
||||
// Setup.
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testReset();
|
||||
TelemetrySend.setServer("http://localhost:" + PingServer.port);
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
|
||||
// Set histograms to expected state.
|
||||
const COUNT_ID = "TELEMETRY_TEST_COUNT";
|
||||
@ -1081,16 +1079,14 @@ add_task(function* test_savedPingsOnShutdown() {
|
||||
// the former on Android.
|
||||
const expectedPingCount = (gIsAndroid) ? 1 : 2;
|
||||
// Assure that we store the ping properly when saving sessions on shutdown.
|
||||
// We make the TelemetrySession shutdown to trigger a session save.
|
||||
// We make the TelemetryController shutdown to trigger a session save.
|
||||
const dir = TelemetryStorage.pingDirectoryPath;
|
||||
yield OS.File.removeDir(dir, {ignoreAbsent: true});
|
||||
yield OS.File.makeDir(dir);
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
|
||||
PingServer.clearRequests();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
const pings = yield PingServer.promiseNextPings(expectedPingCount);
|
||||
|
||||
@ -1142,7 +1138,7 @@ add_task(function* test_savedSessionData() {
|
||||
}
|
||||
|
||||
// Start TelemetrySession so that it loads the session data file.
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
Assert.equal(0, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_LOAD").sum);
|
||||
Assert.equal(0, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_PARSE").sum);
|
||||
Assert.equal(0, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_VALIDATION").sum);
|
||||
@ -1150,7 +1146,7 @@ add_task(function* test_savedSessionData() {
|
||||
// Watch a test preference, trigger and environment change and wait for it to propagate.
|
||||
// _watchPreferences triggers a subsession notification
|
||||
fakeNow(new Date(2050, 1, 1, 12, 0, 0));
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
let changePromise = new Promise(resolve =>
|
||||
TelemetryEnvironment.registerChangeListener("test_fake_change", resolve));
|
||||
Preferences.set(PREF_TEST, 1);
|
||||
@ -1159,7 +1155,7 @@ add_task(function* test_savedSessionData() {
|
||||
|
||||
let payload = TelemetrySession.getPayload();
|
||||
Assert.equal(payload.info.profileSubsessionCounter, expectedSubsessions);
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
|
||||
// Restore the UUID generator so we don't mess with other tests.
|
||||
fakeGenerateUUID(generateUUID, generateUUID);
|
||||
@ -1180,7 +1176,7 @@ add_task(function* test_sessionData_ShortSession() {
|
||||
const SESSION_STATE_PATH = OS.Path.join(DATAREPORTING_PATH, "session-state.json");
|
||||
|
||||
// Shut down Telemetry and remove the session state file.
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testReset();
|
||||
yield OS.File.remove(SESSION_STATE_PATH, { ignoreAbsent: true });
|
||||
getHistogram("TELEMETRY_SESSIONDATA_FAILED_LOAD").clear();
|
||||
getHistogram("TELEMETRY_SESSIONDATA_FAILED_PARSE").clear();
|
||||
@ -1192,8 +1188,8 @@ add_task(function* test_sessionData_ShortSession() {
|
||||
|
||||
// We intentionally don't wait for the setup to complete and shut down to simulate
|
||||
// short sessions. We expect the profile subsession counter to be 1.
|
||||
TelemetrySession.reset();
|
||||
yield TelemetrySession.shutdown();
|
||||
TelemetryController.testReset();
|
||||
yield TelemetryController.testShutdown();
|
||||
|
||||
Assert.equal(1, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_LOAD").sum);
|
||||
Assert.equal(0, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_PARSE").sum);
|
||||
@ -1202,9 +1198,9 @@ add_task(function* test_sessionData_ShortSession() {
|
||||
// Restore the UUID generation functions.
|
||||
fakeGenerateUUID(generateUUID, generateUUID);
|
||||
|
||||
// Start TelemetrySession so that it loads the session data file. We expect the profile
|
||||
// Start TelemetryController so that it loads the session data file. We expect the profile
|
||||
// subsession counter to be incremented by 1 again.
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// We expect 2 profile subsession counter updates.
|
||||
let payload = TelemetrySession.getPayload();
|
||||
@ -1230,8 +1226,8 @@ add_task(function* test_invalidSessionData() {
|
||||
OS.File.writeAtomic(dataFilePath, unparseableData,
|
||||
{encoding: "utf-8", tmpPath: dataFilePath + ".tmp"});
|
||||
|
||||
// Start TelemetrySession so that it loads the session data file.
|
||||
yield TelemetrySession.reset();
|
||||
// Start TelemetryController so that it loads the session data file.
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// The session data file should not load. Only expect the current subsession.
|
||||
Assert.equal(0, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_LOAD").sum);
|
||||
@ -1251,8 +1247,8 @@ add_task(function* test_invalidSessionData() {
|
||||
const expectedSubsessionUUID = "009fd1ad-b85e-4817-b3e5-000000003785";
|
||||
fakeGenerateUUID(() => expectedSessionUUID, () => expectedSubsessionUUID);
|
||||
|
||||
// Start TelemetrySession so that it loads the session data file.
|
||||
yield TelemetrySession.reset();
|
||||
// Start TelemetryController so that it loads the session data file.
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
let payload = TelemetrySession.getPayload();
|
||||
Assert.equal(payload.info.profileSubsessionCounter, expectedSubsessions);
|
||||
@ -1260,7 +1256,7 @@ add_task(function* test_invalidSessionData() {
|
||||
Assert.equal(1, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_PARSE").sum);
|
||||
Assert.equal(1, getSnapshot("TELEMETRY_SESSIONDATA_FAILED_VALIDATION").sum);
|
||||
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
|
||||
// Restore the UUID generator so we don't mess with other tests.
|
||||
fakeGenerateUUID(generateUUID, generateUUID);
|
||||
@ -1288,7 +1284,7 @@ add_task(function* test_abortedSession() {
|
||||
fakeNow(now);
|
||||
// Fake scheduler functions to control aborted-session flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
Assert.ok((yield OS.File.exists(DATAREPORTING_PATH)),
|
||||
"Telemetry must create the aborted session directory when starting.");
|
||||
@ -1325,34 +1321,32 @@ add_task(function* test_abortedSession() {
|
||||
Assert.notEqual(abortedSessionPing.id, updatedAbortedSessionPing.id);
|
||||
Assert.notEqual(abortedSessionPing.creationDate, updatedAbortedSessionPing.creationDate);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
Assert.ok(!(yield OS.File.exists(ABORTED_FILE)),
|
||||
"No aborted session ping must be available after a shutdown.");
|
||||
|
||||
// Write the ping to the aborted-session file. TelemetrySession will add it to the
|
||||
// saved pings directory when it starts.
|
||||
yield TelemetryStorage.savePingToFile(abortedSessionPing, ABORTED_FILE, false);
|
||||
Assert.ok((yield OS.File.exists(ABORTED_FILE)),
|
||||
"The aborted session ping must exist in the aborted session ping directory.");
|
||||
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
// TODO: Remove the TelemetrySend manual setup when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
Assert.ok(!(yield OS.File.exists(ABORTED_FILE)),
|
||||
"The aborted session ping must be removed from the aborted session ping directory.");
|
||||
|
||||
// Restarting Telemetry again to trigger sending pings in TelemetrySend.
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// We should have received an aborted-session ping.
|
||||
const receivedPing = yield PingServer.promiseNextPing();
|
||||
Assert.equal(receivedPing.type, PING_TYPE_MAIN, "Should have the correct type");
|
||||
Assert.equal(receivedPing.payload.info.reason, REASON_ABORTED_SESSION, "Ping should have the correct reason");
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_abortedSession_Shutdown() {
|
||||
@ -1367,10 +1361,7 @@ add_task(function* test_abortedSession_Shutdown() {
|
||||
let now = fakeNow(2040, 1, 1, 0, 0, 0);
|
||||
// Fake scheduler functions to control aborted-session flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
// TODO: Remove the TelemetrySend manual setup/reset when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
Assert.ok((yield OS.File.exists(DATAREPORTING_PATH)),
|
||||
"Telemetry must create the aborted session directory when starting.");
|
||||
@ -1388,9 +1379,7 @@ add_task(function* test_abortedSession_Shutdown() {
|
||||
// not found) do not compromise the shutdown.
|
||||
yield OS.File.remove(ABORTED_FILE);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_abortedDailyCoalescing() {
|
||||
@ -1412,10 +1401,9 @@ add_task(function* test_abortedDailyCoalescing() {
|
||||
|
||||
// Fake scheduler functions to control aborted-session flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
// TODO: Remove the TelemetrySend manual setup/reset when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield TelemetrySession.reset();
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
Assert.ok((yield OS.File.exists(DATAREPORTING_PATH)),
|
||||
"Telemetry must create the aborted session directory when starting.");
|
||||
@ -1444,9 +1432,7 @@ add_task(function* test_abortedDailyCoalescing() {
|
||||
Assert.equal(abortedSessionPing.payload.info.sessionId, dailyPing.payload.info.sessionId);
|
||||
Assert.equal(abortedSessionPing.payload.info.subsessionId, dailyPing.payload.info.subsessionId);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_schedulerComputerSleep() {
|
||||
@ -1457,10 +1443,8 @@ add_task(function* test_schedulerComputerSleep() {
|
||||
|
||||
const ABORTED_FILE = OS.Path.join(DATAREPORTING_PATH, ABORTED_PING_FILE_NAME);
|
||||
|
||||
clearPendingPings();
|
||||
// TODO: Remove the TelemetrySend manual setup when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield clearPendingPings();
|
||||
yield TelemetryController.testReset();
|
||||
PingServer.clearRequests();
|
||||
|
||||
// Remove any aborted-session ping from the previous tests.
|
||||
@ -1471,7 +1455,7 @@ add_task(function* test_schedulerComputerSleep() {
|
||||
fakeNow(nowDate);
|
||||
let schedulerTickCallback = null;
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Set the current time 3 days in the future at midnight, before running the callback.
|
||||
let future = futureDate(nowDate, MS_IN_ONE_DAY * 3);
|
||||
@ -1486,9 +1470,7 @@ add_task(function* test_schedulerComputerSleep() {
|
||||
Assert.ok((yield OS.File.exists(ABORTED_FILE)),
|
||||
"There must be an aborted session ping.");
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_schedulerEnvironmentReschedules() {
|
||||
@ -1506,17 +1488,15 @@ add_task(function* test_schedulerEnvironmentReschedules() {
|
||||
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
// TODO: Remove the TelemetrySend manual setup/reset when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Set a fake current date and start Telemetry.
|
||||
let nowDate = new Date(2060, 10, 18, 0, 0, 0);
|
||||
fakeNow(nowDate);
|
||||
let schedulerTickCallback = null;
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
TelemetryEnvironment._watchPreferences(PREFS_TO_WATCH);
|
||||
yield TelemetryController.testReset();
|
||||
TelemetryEnvironment.testWatchPreferences(PREFS_TO_WATCH);
|
||||
|
||||
// Set the current time at midnight.
|
||||
let future = futureDate(nowDate, MS_IN_ONE_DAY);
|
||||
@ -1536,10 +1516,7 @@ add_task(function* test_schedulerEnvironmentReschedules() {
|
||||
// Execute one scheduler tick. It should not trigger a daily ping.
|
||||
Assert.ok(!!schedulerTickCallback);
|
||||
yield schedulerTickCallback();
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_schedulerNothingDue() {
|
||||
@ -1553,9 +1530,7 @@ add_task(function* test_schedulerNothingDue() {
|
||||
// Remove any aborted-session ping from the previous tests.
|
||||
yield OS.File.removeDir(DATAREPORTING_PATH, { ignoreAbsent: true });
|
||||
yield clearPendingPings();
|
||||
// TODO: Remove the TelemetrySend manual setup/reset when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// We don't expect to receive any ping in this test, so assert if we do.
|
||||
PingServer.registerPingHandler((req, res) => {
|
||||
@ -1568,7 +1543,7 @@ add_task(function* test_schedulerNothingDue() {
|
||||
fakeNow(nowDate);
|
||||
let schedulerTickCallback = null;
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Delay the callback execution to a time when no ping should be due.
|
||||
let nothingDueDate = futureDate(nowDate, ABORTED_SESSION_UPDATE_INTERVAL_MS / 2);
|
||||
@ -1580,9 +1555,7 @@ add_task(function* test_schedulerNothingDue() {
|
||||
// Check that no aborted session ping was written to disk.
|
||||
Assert.ok(!(yield OS.File.exists(ABORTED_FILE)));
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
PingServer.resetPingHandler();
|
||||
});
|
||||
|
||||
@ -1592,15 +1565,12 @@ add_task(function* test_pingExtendedStats() {
|
||||
"addonHistograms", "addonDetails", "UIMeasurements", "webrtc"
|
||||
];
|
||||
|
||||
// Disable sending extended statistics.
|
||||
Telemetry.canRecordExtended = false;
|
||||
|
||||
// Reset telemetry and disable sending extended statistics.
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
// TODO: Remove the TelemetrySend manual setup/reset when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
Telemetry.canRecordExtended = false;
|
||||
|
||||
yield sendPing();
|
||||
|
||||
let ping = yield PingServer.promiseNextPing();
|
||||
@ -1626,7 +1596,6 @@ add_task(function* test_pingExtendedStats() {
|
||||
Telemetry.canRecordExtended = true;
|
||||
|
||||
// Send a new ping that should contain the extended data.
|
||||
yield TelemetrySession.reset();
|
||||
yield sendPing();
|
||||
ping = yield PingServer.promiseNextPing();
|
||||
checkPingFormat(ping, PING_TYPE_MAIN, true, true);
|
||||
@ -1659,7 +1628,7 @@ add_task(function* test_schedulerUserIdle() {
|
||||
fakeSchedulerTimer((callback, timeout) => {
|
||||
schedulerTimeout = timeout;
|
||||
}, () => {});
|
||||
yield TelemetrySession.reset();
|
||||
yield TelemetryController.testReset();
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
|
||||
@ -1685,9 +1654,7 @@ add_task(function* test_schedulerUserIdle() {
|
||||
fakeIdleNotification("idle");
|
||||
Assert.equal(schedulerTimeout, 10 * 60 * 1000);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_DailyDueAndIdle() {
|
||||
@ -1696,12 +1663,8 @@ add_task(function* test_DailyDueAndIdle() {
|
||||
return;
|
||||
}
|
||||
|
||||
yield TelemetrySession.reset();
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
// TODO: Remove the TelemetrySend setup when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
|
||||
let receivedPingRequest = null;
|
||||
// Register a ping handler that will assert when receiving multiple daily pings.
|
||||
@ -1710,12 +1673,14 @@ add_task(function* test_DailyDueAndIdle() {
|
||||
receivedPingRequest = req;
|
||||
});
|
||||
|
||||
// Faking scheduler timer has to happen before resetting TelemetryController
|
||||
// to be effective.
|
||||
let schedulerTickCallback = null;
|
||||
let now = new Date(2030, 1, 1, 0, 0, 0);
|
||||
fakeNow(now);
|
||||
// Fake scheduler functions to control daily collection flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.setup();
|
||||
yield TelemetryController.testReset();
|
||||
|
||||
// Trigger the daily ping.
|
||||
let firstDailyDue = new Date(2030, 1, 2, 0, 0, 0);
|
||||
@ -1740,9 +1705,7 @@ add_task(function* test_DailyDueAndIdle() {
|
||||
checkPingFormat(receivedPing, PING_TYPE_MAIN, true, true);
|
||||
Assert.equal(receivedPing.payload.info.reason, REASON_DAILY);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* test_userIdleAndSchedlerTick() {
|
||||
@ -1751,13 +1714,6 @@ add_task(function* test_userIdleAndSchedlerTick() {
|
||||
return;
|
||||
}
|
||||
|
||||
yield TelemetrySession.reset();
|
||||
yield clearPendingPings();
|
||||
PingServer.clearRequests();
|
||||
// TODO: Remove the TelemetrySend setup when bug 1145188 lands.
|
||||
yield TelemetrySend.setup(true);
|
||||
yield TelemetrySend.reset();
|
||||
|
||||
let receivedPingRequest = null;
|
||||
// Register a ping handler that will assert when receiving multiple daily pings.
|
||||
PingServer.registerPingHandler(req => {
|
||||
@ -1770,7 +1726,9 @@ add_task(function* test_userIdleAndSchedlerTick() {
|
||||
fakeNow(now);
|
||||
// Fake scheduler functions to control daily collection flow in tests.
|
||||
fakeSchedulerTimer(callback => schedulerTickCallback = callback, () => {});
|
||||
yield TelemetrySession.setup();
|
||||
yield clearPendingPings();
|
||||
yield TelemetryController.testReset();
|
||||
PingServer.clearRequests();
|
||||
|
||||
// Move the current date/time to midnight.
|
||||
let firstDailyDue = new Date(2030, 1, 2, 0, 0, 0);
|
||||
@ -1795,9 +1753,7 @@ add_task(function* test_userIdleAndSchedlerTick() {
|
||||
checkPingFormat(receivedPing, PING_TYPE_MAIN, true, true);
|
||||
Assert.equal(receivedPing.payload.info.reason, REASON_DAILY);
|
||||
|
||||
// TODO: Remove the TelemetrySend manual shutdown when bug 1145188 lands.
|
||||
yield TelemetrySend.shutdown();
|
||||
yield TelemetrySession.shutdown();
|
||||
yield TelemetryController.testShutdown();
|
||||
});
|
||||
|
||||
add_task(function* stopServer(){
|
||||
|
@ -32,13 +32,13 @@ function getSimpleMeasurementsFromTelemetryController() {
|
||||
}
|
||||
|
||||
function initialiseTelemetry() {
|
||||
return TelemetryController.setup().then(TelemetrySession.setup);
|
||||
return TelemetryController.testSetup();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// Telemetry needs the AddonManager.
|
||||
loadAddonManager();
|
||||
// Make profile available for |TelemetrySession.shutdown()|.
|
||||
// Make profile available for |TelemetryController.testShutdown()|.
|
||||
do_get_profile();
|
||||
|
||||
do_test_pending();
|
||||
@ -85,7 +85,7 @@ add_task(function* actualTest() {
|
||||
do_check_true(simpleMeasurements.bar > 1); // bar was included
|
||||
do_check_eq(undefined, simpleMeasurements.baz); // baz wasn't included since it wasn't added
|
||||
|
||||
yield TelemetrySession.shutdown(false);
|
||||
yield TelemetryController.testShutdown();
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
|
@ -39,8 +39,8 @@ function run_test()
|
||||
crashReporter.appendAppNotesToCrashReport("MoreJunk");
|
||||
// TelemetrySession setup will trigger the session annotation
|
||||
let scope = {};
|
||||
Components.utils.import("resource://gre/modules/TelemetrySession.jsm", scope);
|
||||
scope.TelemetrySession.setup();
|
||||
Components.utils.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
scope.TelemetryController.testSetup();
|
||||
},
|
||||
function(mdump, extra) {
|
||||
do_check_eq(extra.TestKey, "TestValue");
|
||||
|
@ -28,8 +28,8 @@ add_task(function* test_main_process_crash() {
|
||||
function() {
|
||||
// TelemetrySession setup will trigger the session annotation
|
||||
let scope = {};
|
||||
Components.utils.import("resource://gre/modules/TelemetrySession.jsm", scope);
|
||||
scope.TelemetrySession.setup();
|
||||
Components.utils.import("resource://gre/modules/TelemetryController.jsm", scope);
|
||||
scope.TelemetryController.testSetup();
|
||||
crashType = CrashTestUtils.CRASH_RUNTIMEABORT;
|
||||
crashReporter.annotateCrashReport("ShutdownProgress", "event-test");
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user