Bug 1463673 - Add the expected argument to Assert.throws/rejects for toolkit/components/telemetry. r?gfritzsche
MozReview-Commit-ID: KclrG4BfCgp
--- a/toolkit/components/telemetry/tests/unit/test_PingAPI.js
+++ b/toolkit/components/telemetry/tests/unit/test_PingAPI.js
@@ -211,16 +211,17 @@ add_task(async function test_archiveClea
let expectedPrunedInfo = [];
let expectedNotPrunedInfo = [];
let checkArchive = async function() {
// Check that the pruned pings are not on disk anymore.
for (let prunedInfo of expectedPrunedInfo) {
await Assert.rejects(TelemetryArchive.promiseArchivedPingById(prunedInfo.id),
+ /TelemetryStorage.loadArchivedPing - no ping with id/,
"Ping " + prunedInfo.id + " should have been pruned.");
const pingPath =
TelemetryStorage._testGetArchivedPingPath(prunedInfo.id, prunedInfo.creationDate, PING_TYPE);
Assert.ok(!(await OS.File.exists(pingPath)), "The ping should not be on the disk anymore.");
}
// Check that the expected pings are there.
for (let expectedInfo of expectedNotPrunedInfo) {
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
@@ -537,16 +537,17 @@ add_task(async function test_sendNewProf
let req = await nextReq;
let ping = decodeRequestPayload(req);
checkPingFormat(ping, NEWPROFILE_PING_TYPE, true, true);
Assert.equal(ping.payload.reason, "startup",
"The new-profile ping generated after startup must have the correct reason");
// Check that is not sent with the pingsender during startup.
Assert.throws(() => req.getHeader("X-PingSender-Version"),
+ /NS_ERROR_NOT_AVAILABLE/,
"Should not have used the pingsender.");
// Make sure that the new-profile ping is sent at shutdown if it wasn't sent before.
await resetTest();
await OS.File.remove(stateFilePath, { ignoreAbsent: true });
Preferences.reset(PREF_NEWPROFILE_DELAY);
nextReq = PingServer.promiseNextRequest();
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js
@@ -261,16 +261,17 @@ add_task(async function test_discardedFo
// Generate a 2MB string to use as the ping payload.
payload: overSizedPayload,
};
// Test loadPendingPing.
await TelemetryStorage.savePendingPing(OVERSIZED_PING);
// Try to manually load the oversized ping.
await Assert.rejects(TelemetryStorage.loadPendingPing(OVERSIZED_PING_ID),
+ /loadPendingPing - exceeded the maximum ping size/,
"The oversized ping should have been pruned.");
let ping = await PingServer.promiseNextPing();
checkHealthPingStructure(ping, {
[TelemetryHealthPing.FailureType.DISCARDED_FOR_SIZE]: {
"<unknown>": 1
},
"os": TelemetryHealthPing.OsInfo,
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -415,17 +415,19 @@ add_task(async function test_evictedOnSe
Assert.equal(histEvicted.snapshot().sum, 1,
"Telemetry must report a ping evicted due to server errors");
Assert.deepEqual(histSuccess.snapshot().counts, [0, 1, 0]);
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 1);
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0);
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), 0);
// The ping should not be persisted.
- await Assert.rejects(TelemetryStorage.loadPendingPing(pingId), "The ping must not be persisted.");
+ await Assert.rejects(TelemetryStorage.loadPendingPing(pingId),
+ /TelemetryStorage.loadPendingPing - no ping with id/,
+ "The ping must not be persisted.");
// Reset the ping handler and submit a new ping.
PingServer.resetPingHandler();
pingId = await TelemetryController.submitExternalPing(TEST_TYPE, {});
let ping = await PingServer.promiseNextPings(1);
Assert.equal(ping[0].id, pingId, "The correct ping must be received");
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySendOldPings.js
@@ -270,31 +270,33 @@ add_task(async function test_corrupted_p
Assert.equal(h.sum, 0, "Telemetry must not report a pending ping parse failure");
// Delete it from the disk, so that its id will be kept in the cache but it will
// fail loading the file.
await OS.File.remove(getSavePathForPingId(pendingPingId));
// Try to load a pending ping which isn't there anymore.
await Assert.rejects(TelemetryStorage.loadPendingPing(pendingPingId),
+ /PingReadError/,
"Telemetry must fail loading a ping which isn't there");
h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_READ").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report a pending ping load failure");
h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_PARSE").snapshot();
Assert.equal(h.sum, 0, "Telemetry must not report a pending ping parse failure");
// Save a new ping, so that it gets in the pending pings cache.
pendingPingId = await TelemetryController.addPendingPing(TEST_TYPE, {}, {});
// Overwrite it with a corrupted JSON file and then try to load it.
const INVALID_JSON = "{ invalid,JSON { {1}";
await OS.File.writeAtomic(getSavePathForPingId(pendingPingId), INVALID_JSON, { encoding: "utf-8" });
// Try to load the ping with the corrupted JSON content.
await Assert.rejects(TelemetryStorage.loadPendingPing(pendingPingId),
+ /PingParseError/,
"Telemetry must fail loading a corrupted ping");
h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_READ").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report a pending ping load failure");
h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_PARSE").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report a pending ping parse failure");
let exists = await OS.File.exists(getSavePathForPingId(pendingPingId));
@@ -397,16 +399,17 @@ add_task(async function test_pendingPing
let expectedPrunedPings = [];
let expectedNotPrunedPings = [];
let checkPendingPings = async function() {
// Check that the pruned pings are not on disk anymore.
for (let prunedPingId of expectedPrunedPings) {
await Assert.rejects(TelemetryStorage.loadPendingPing(prunedPingId),
+ /TelemetryStorage.loadPendingPing - no ping with id/,
"Ping " + prunedPingId + " should have been pruned.");
const pingPath = getSavePathForPingId(prunedPingId);
Assert.ok(!(await OS.File.exists(pingPath)), "The ping should not be on the disk anymore.");
}
// Check that the expected pings are there.
for (let expectedPingId of expectedNotPrunedPings) {
Assert.ok((await TelemetryStorage.loadPendingPing(expectedPingId)),
@@ -504,16 +507,17 @@ add_task(async function test_pendingPing
await TelemetryStorage.savePendingPing(OVERSIZED_PING);
// Reset the histograms.
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").clear();
Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").clear();
// Try to manually load the oversized ping.
await Assert.rejects(TelemetryStorage.loadPendingPing(OVERSIZED_PING_ID),
+ /loadPendingPing - exceeded the maximum ping size/,
"The oversized ping should have been pruned.");
Assert.ok(!(await OS.File.exists(getSavePathForPingId(OVERSIZED_PING_ID))),
"The ping should not be on the disk anymore.");
// Make sure we're correctly updating the related histograms.
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report 1 oversized ping in the pending pings directory.");
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").snapshot();