Bug 1518713 - Make it easier to update the GC telemetry unit test r=florian
authorPaul Bone <pbone@mozilla.com>
Mon, 07 Jan 2019 22:19:13 +1100
changeset 510287 4d91186df5379e11f089f32869a303c44cd172b0
parent 510286 f950f9e241219cec29a233a020825037192ccee9
child 510288 9d40c98b9efbf728f7fa542150ca8023dfbee022
child 510341 a861fff5d00c71af2719e40b6cc512f5af5bc598
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1518713
milestone66.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 1518713 - Make it easier to update the GC telemetry unit test r=florian By refactoring this test code we can more easily adjust the number of fields there are supposed to be in these objects.
toolkit/components/telemetry/tests/unit/test_TelemetryGC.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryGC.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryGC.js
@@ -12,63 +12,70 @@ function do_register_cleanup() {
 
 /*
  * These tests are very basic, my goal was to add enough testing to support
  * a change made in Bug 1424760.  TODO Bug 1429635 for adding more extensive
  * tests and deleting this comment.
  */
 
 function run_test() {
+  // The limit on the number of fields in a GCMajor object.
+  const limit = 24;
+
+  // The number of fields that the make_gc() test function generates.
+  const make_gc_fields = 19;
+
   // Test initialisation
   Assert.ok(GCTelemetry.init(), "Initialize success");
   Assert.ok(!GCTelemetry.init(), "Wont initialize twice");
 
   // Test the basic success path.
 
   // There are currently no entries
   assert_num_entries(0, false);
 
   // Add an entry
   GCTelemetry.observeRaw(make_gc());
   // Get it back.
   assert_num_entries(1, false);
-  Assert.equal(19, Object.keys(get_entry()).length);
+  Assert.equal(make_gc_fields, Object.keys(get_entry()).length);
   // "true" will cause the entry to be clared.
   assert_num_entries(1, true);
   // There are currently no entries.
   assert_num_entries(0, false);
 
   // Test too many fields
   let my_big_gc = make_gc();
   for (let i = 0; i < 100; i++) {
       my_big_gc["new_property_" + i] = "Data";
   }
   GCTelemetry.observeRaw(my_big_gc);
   // Assert that it was recorded but has only 7 fields.
   Assert.equal(7, Object.keys(get_entry()).length);
   assert_num_entries(1, true);
   assert_num_entries(0, false);
 
-  // Exactly the limit of fields.
-  let my_gc_24 = make_gc();
-  for (let i = 0; i < 5; i++) {
-      my_gc_24["new_property_" + i] = "Data";
+  let my_gc_exact = make_gc();
+  Assert.equal(make_gc_fields, Object.keys(my_gc_exact).length);
+
+  for (let i = 0; i < limit - make_gc_fields; i++) {
+      my_gc_exact["new_property_" + i] = "Data";
   }
-  GCTelemetry.observeRaw(my_gc_24);
-  // Assert that it was recorded has all 24 fields.
-  Assert.equal(24, Object.keys(get_entry()).length);
+  GCTelemetry.observeRaw(my_gc_exact);
+  // Assert that it was recorded has all the fields.
+  Assert.equal(limit, Object.keys(get_entry()).length);
   assert_num_entries(1, true);
   assert_num_entries(0, false);
 
   // Exactly too many fields.
-  let my_gc_25 = make_gc();
-  for (let i = 0; i < 6; i++) {
-      my_gc_25["new_property_" + i] = "Data";
+  let my_gc_too_many = make_gc();
+  for (let i = 0; i < limit - make_gc_fields + 1; i++) {
+      my_gc_too_many["new_property_" + i] = "Data";
   }
-  GCTelemetry.observeRaw(my_gc_25);
+  GCTelemetry.observeRaw(my_gc_too_many);
   // Assert that it was recorded but has only 7 fields.
   Assert.equal(7, Object.keys(get_entry()).length);
   assert_num_entries(1, true);
   assert_num_entries(0, false);
 }
 
 function assert_num_entries(expect, clear) {
   let entries = GCTelemetry.entries("main", clear);