bug 1460595 - Test "event" ping event storage r=Dexter,janerik
authorChris H-C <chutten@mozilla.com>
Fri, 11 May 2018 16:13:18 -0400
changeset 423719 f9ce3e37a291
parent 423718 264376b1bd3f
child 423720 e2242d1730a3
push id34191
push userrgurzau@mozilla.com
push dateTue, 26 Jun 2018 21:53:37 +0000
treeherdermozilla-central@1c235a552c32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter, janerik
bugs1460595
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1460595 - Test "event" ping event storage r=Dexter,janerik I added checks that the new topic was appropriately notified and that storage doesn't truncate upon hitting the limit, also covering the case when there is a specified event limit for return. MozReview-Commit-ID: FoSVvi7XSeM
toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
@@ -1,12 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 
+ChromeUtils.defineModuleGetter(this, "TestUtils", "resource://testing-common/TestUtils.jsm");
+
 const OPTIN = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN;
 const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
 
 function checkEventFormat(events) {
   Assert.ok(Array.isArray(events), "Events should be serialized to an array.");
   for (let e of events) {
     Assert.ok(Array.isArray(e), "Event should be an array.");
     Assert.greaterOrEqual(e.length, 4, "Event should have at least 4 elements.");
@@ -245,16 +247,37 @@ add_task(async function test_clear() {
   // The events are cleared by passing the respective flag.
   let snapshot = Telemetry.snapshotEvents(OPTIN, true);
   Assert.ok(("parent" in snapshot), "Should have entry for main process.");
   Assert.equal(snapshot.parent.length, 2 * COUNT, `Should have recorded ${2 * COUNT} events.`);
 
   // Now the events should be cleared.
   snapshot = Telemetry.snapshotEvents(OPTIN, false);
   Assert.equal(Object.keys(snapshot).length, 0, `Should have cleared the events.`);
+
+  for (let i = 0; i < COUNT; ++i) {
+    Telemetry.recordEvent("telemetry.test", "test1", "object1");
+    Telemetry.recordEvent("telemetry.test.second", "test", "object1");
+  }
+  snapshot = Telemetry.snapshotEvents(OPTIN, true, 5);
+  Assert.ok(("parent" in snapshot), "Should have entry for main process.");
+  Assert.equal(snapshot.parent.length, 5, "Should have returned 5 events");
+  snapshot = Telemetry.snapshotEvents(OPTIN, false);
+  Assert.ok(("parent" in snapshot), "Should have entry for main process.");
+  Assert.equal(snapshot.parent.length, (2 * COUNT) - 5, `Should have returned ${(2 * COUNT) - 5} events`);
+
+  Telemetry.recordEvent("telemetry.test", "test1", "object1");
+  snapshot = Telemetry.snapshotEvents(OPTIN, false, 5);
+  Assert.ok(("parent" in snapshot), "Should have entry for main process.");
+  Assert.equal(snapshot.parent.length, 5, "Should have returned 5 events");
+  snapshot = Telemetry.snapshotEvents(OPTIN, true);
+  Assert.ok(("parent" in snapshot), "Should have entry for main process.");
+  Assert.equal(snapshot.parent.length, (2 * COUNT) - 5 + 1, `Should have returned ${(2 * COUNT) - 5 + 1} events`);
+
+
 });
 
 add_task(async function test_expiry() {
   Telemetry.clearEvents();
 
   // Recording call with event that is expired by version.
   Telemetry.recordEvent("telemetry.test", "expired_version", "object1");
   let snapshot = Telemetry.snapshotEvents(OPTIN, true);
@@ -289,30 +312,34 @@ add_task(async function test_invalidPara
   Telemetry.recordEvent("telemetry.test", "test1", "object1", null, {"key3": 1});
   snapshot = Telemetry.snapshotEvents(OPTIN, true);
   Assert.equal(Object.keys(snapshot).length, 0, "Should not record event when extra argument with invalid value type is passed.");
 });
 
 add_task(async function test_storageLimit() {
   Telemetry.clearEvents();
 
+  let limitReached = TestUtils.topicObserved("event-telemetry-storage-limit-reached");
   // Record more events than the storage limit allows.
   let LIMIT = 1000;
   let COUNT = LIMIT + 10;
   for (let i = 0; i < COUNT; ++i) {
     Telemetry.recordEvent("telemetry.test", "test1", "object1", String(i));
   }
 
+  await limitReached;
+  Assert.ok(true, "Topic was notified when event limit was reached");
+
   // Check that the right events were recorded.
   let snapshot = Telemetry.snapshotEvents(OPTIN, true);
   Assert.ok(("parent" in snapshot), "Should have entry for main process.");
   let events = snapshot.parent;
-  Assert.equal(events.length, LIMIT, `Should have only recorded ${LIMIT} events`);
+  Assert.equal(events.length, COUNT, `Should have only recorded all ${COUNT} events`);
   Assert.ok(events.every((e, idx) => e[4] === String(idx)),
-            "Should have recorded all events from before hitting the limit.");
+            "Should have recorded all events.");
 });
 
 add_task(async function test_valueLimits() {
   Telemetry.clearEvents();
 
   // Record values that are at or over the limits for string lengths.
   let LIMIT = 80;
   let expected = [