Bug 1555798 - Test that registering and recording dynamic events and scalars together does not crash. r=Dexter a=jcristau
authorChris H-C <chutten@mozilla.com>
Fri, 31 May 2019 15:01:23 +0000
changeset 536640 83245ccc42c043747164a97773095fd61632beae
parent 536639 c18af2278a4d3027bdbfc07454e99c6611862377
child 536641 b9e525d8b1aa6659c6cc95956dafae65c28daa62
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter, jcristau
bugs1555798
milestone68.0
Bug 1555798 - Test that registering and recording dynamic events and scalars together does not crash. r=Dexter a=jcristau Depends on D33274 Differential Revision: https://phabricator.services.mozilla.com/D33275
toolkit/components/telemetry/tests/unit/test_bug1555798.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_bug1555798.js
@@ -0,0 +1,47 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+ChromeUtils.defineModuleGetter(this, "TelemetryTestUtils",
+                             "resource://testing-common/TelemetryTestUtils.jsm");
+
+add_task(async function test_bug1555798() {
+  /*
+  The idea behind this bug is that the registration of dynamic scalars causes
+  the position of the scalarinfo for telemetry.dynamic_events_count to move
+  which causes things to asplode.
+
+  So to test this we'll be registering two dynamic events, recording to one of
+  the events (to ensure the Scalar for event1 is allocated from the unmoved
+  DynamicScalarInfo&), registering several dynamic scalars to cause the
+  nsTArray of DynamicScalarInfo to realloc, and then recording to the second
+  event to make the Event Summary Scalar for event2 try to allocate from where
+  the DynamicScalarInfo used to be.
+  */
+  Telemetry.clearEvents();
+
+  const DYNAMIC_CATEGORY = "telemetry.test.dynamic.event";
+  Telemetry.registerEvents(DYNAMIC_CATEGORY, {
+    "an_event": {
+      methods: ["a_method"],
+      objects: ["an_object", "another_object"],
+      record_on_release: true,
+      expired: false,
+    },
+  });
+  Telemetry.recordEvent(DYNAMIC_CATEGORY, "a_method", "an_object");
+
+  for (let i = 0; i < 100; ++i) {
+    Telemetry.registerScalars("telemetry.test.dynamic" + i, {
+      "scalar_name": {
+        kind: Ci.nsITelemetry.SCALAR_TYPE_COUNT,
+        record_on_release: true,
+      },
+    });
+    Telemetry.scalarAdd("telemetry.test.dynamic" + i + ".scalar_name", 1);
+  }
+
+  Telemetry.recordEvent(DYNAMIC_CATEGORY, "a_method", "another_object");
+
+  TelemetryTestUtils.assertNumberOfEvents(2, {}, {process: "dynamic"});
+});
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -98,8 +98,9 @@ skip-if = (os == "android") || (os == "l
 run-if = nightly_build && (os == 'win')
 [test_EcosystemTelemetry.js]
 skip-if = (os == "linux" && bits == 32) # lack of support on test runners (see bug 1310703, comment78)
 [test_EventPing.js]
 [test_EventPing_disabled.js]
 tags = coverage
 [test_CoveragePing.js]
 [test_PrioPing.js]
+[test_bug1555798.js]