Bug 1186955 - Add test coverage. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-07-30 14:40:00 +02:00
parent bad1a8bb5e
commit 22f70b5d0e
5 changed files with 119 additions and 0 deletions

View File

@ -287,6 +287,17 @@ function promiseRejects(promise) {
return promise.then(() => false, () => true);
}
// Generates a random string of at least a specific length.
function generateRandomString(length) {
let string = "";
while (string.length < length) {
string += Math.random().toString(36);
}
return string.substring(0, length);
}
if (runningInParent) {
// Set logging preferences for all the tests.
Services.prefs.setCharPref("toolkit.telemetry.log.level", "Trace");

View File

@ -200,6 +200,9 @@ add_task(function* test_archiveCleanup() {
Telemetry.getHistogramById("TELEMETRY_ARCHIVE_SCAN_PING_COUNT").clear();
Telemetry.getHistogramById("TELEMETRY_ARCHIVE_DIRECTORIES_COUNT").clear();
// Also reset these histograms to make sure normal sized pings don't get counted.
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_ARCHIVED").clear();
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();
@ -363,6 +366,39 @@ add_task(function* test_archiveCleanup() {
yield TelemetryStorage.testCleanupTaskPromise();
yield TelemetryArchive.promiseArchivedPingList();
yield checkArchive();
const OVERSIZED_PING_ID = "9b21ec8f-f762-4d28-a2c1-44e1c4694f24";
// Create and archive an oversized, uncompressed, ping.
const OVERSIZED_PING = {
id: OVERSIZED_PING_ID,
type: PING_TYPE,
creationDate: (new Date()).toISOString(),
// Generate a ~2MB string to use as the payload.
payload: generateRandomString(2 * 1024 * 1024)
};
yield TelemetryArchive.promiseArchivePing(OVERSIZED_PING);
// Get the size of the archived ping.
const oversizedPingPath =
TelemetryStorage._testGetArchivedPingPath(OVERSIZED_PING.id, new Date(OVERSIZED_PING.creationDate), PING_TYPE) + "lz4";
const archivedPingSizeMB = Math.floor((yield OS.File.stat(oversizedPingPath)).size / 1024 / 1024);
// We expect the oversized ping to be pruned when scanning the archive.
expectedPrunedInfo.push({ id: OVERSIZED_PING_ID, creationDate: new Date(OVERSIZED_PING.creationDate) });
// Scan the archive.
yield TelemetryController.reset();
yield TelemetryStorage.testCleanupTaskPromise();
yield TelemetryArchive.promiseArchivedPingList();
// The following also checks that non oversized pings are not removed.
yield checkArchive();
// Make sure we're correctly updating the related histograms.
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_ARCHIVED").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report 1 oversized ping in the archive.");
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_ARCHIVED_PINGS_SIZE_MB").snapshot();
Assert.equal(h.counts[archivedPingSizeMB], 1,
"Telemetry must report the correct size for the oversized ping.");
});
add_task(function* test_clientId() {

View File

@ -238,6 +238,33 @@ add_task(function* test_backoffTimeout() {
Assert.equal(TelemetrySend.pendingPingCount, 0, "Should have no pending pings left");
});
add_task(function* test_discardBigPings() {
const TEST_PING_TYPE = "test-ping-type";
// Generate a 2MB string and create an oversized payload.
const OVERSIZED_PAYLOAD = generateRandomString(2 * 1024 * 1024);
// Reset the histograms.
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND").clear();
Telemetry.getHistogramById("TELEMETRY_DISCARDED_SEND_PINGS_SIZE_MB").clear();
// Submit a ping of a normal size and check that we don't count it in the histogram.
yield TelemetryController.submitExternalPing(TEST_PING_TYPE, { test: "test" });
yield TelemetrySend.testWaitOnOutgoingPings();
let h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND").snapshot();
Assert.equal(h.sum, 0, "Telemetry must report no oversized ping submitted.");
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_SEND_PINGS_SIZE_MB").snapshot();
Assert.equal(h.sum, 0, "Telemetry must report no oversized pings.");
// Submit an oversized ping and check that it gets discarded.
yield TelemetryController.submitExternalPing(TEST_PING_TYPE, OVERSIZED_PAYLOAD);
yield TelemetrySend.testWaitOnOutgoingPings();
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report 1 oversized ping submitted.");
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_SEND_PINGS_SIZE_MB").snapshot();
Assert.equal(h.counts[2], 1, "Telemetry must report a 2MB, oversized, ping submitted.");
});
add_task(function* test_evictedOnServerErrors() {
const TEST_TYPE = "test-evicted";

View File

@ -511,6 +511,48 @@ add_task(function* test_pendingPingsQuota() {
yield TelemetryStorage.testPendingQuotaTaskPromise();
yield checkPendingPings();
const OVERSIZED_PING_ID = "9b21ec8f-f762-4d28-a2c1-44e1c4694f24";
// Create a pending oversized ping.
const OVERSIZED_PING = {
id: OVERSIZED_PING_ID,
type: PING_TYPE,
creationDate: (new Date()).toISOString(),
// Generate a 2MB string to use as the ping payload.
payload: generateRandomString(2 * 1024 * 1024),
};
yield 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.
yield Assert.rejects(TelemetryStorage.loadPendingPing(OVERSIZED_PING_ID),
"The oversized ping should have been pruned.");
Assert.ok(!(yield 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();
Assert.equal(h.counts[2], 1, "Telemetry must report a 2MB, oversized, ping.");
// Save the ping again to check if it gets pruned when scanning the pings directory.
yield TelemetryStorage.savePendingPing(OVERSIZED_PING);
expectedPrunedPings.push(OVERSIZED_PING_ID);
// Scan the pending pings directory.
yield TelemetryController.reset();
yield TelemetryStorage.testPendingQuotaTaskPromise();
yield checkPendingPings();
// Make sure we're correctly updating the related histograms.
h = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").snapshot();
Assert.equal(h.sum, 2, "Telemetry must report 1 oversized ping in the pending pings directory.");
h = Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB").snapshot();
Assert.equal(h.counts[2], 2, "Telemetry must report two 2MB, oversized, pings.");
Services.prefs.setBoolPref(PREF_FHR_UPLOAD, true);
});

View File

@ -933,6 +933,7 @@ add_task(function* test_dailyDuplication() {
return;
}
clearPendingPings();
PingServer.clearRequests();
let schedulerTickCallback = null;
@ -1431,6 +1432,8 @@ add_task(function* test_schedulerComputerSleep() {
const ABORTED_FILE = OS.Path.join(DATAREPORTING_PATH, ABORTED_PING_FILE_NAME);
clearPendingPings();
yield TelemetrySend.reset();
PingServer.clearRequests();
// Remove any aborted-session ping from the previous tests.