Bug 1527614 - Fix a couple of missing assertions in TelemetryTestUtils.jsm. r=chutten
authorMark Banner <standard8@mozilla.com>
Wed, 13 Feb 2019 18:08:32 +0000
changeset 458976 53d7d4732ab95cead72ba1c4e0f13e411aac02d6
parent 458975 324d25d3f933e02c91a97d4c4c3172edc4b8a014
child 458977 ba60c53e260675aec41672efc9da186334d48c89
push id78133
push usermbanner@mozilla.com
push dateWed, 13 Feb 2019 21:10:53 +0000
treeherderautoland@53d7d4732ab9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1527614
milestone67.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 1527614 - Fix a couple of missing assertions in TelemetryTestUtils.jsm. r=chutten Differential Revision: https://phabricator.services.mozilla.com/D19662
toolkit/components/telemetry/tests/utils/TelemetryTestUtils.jsm
--- a/toolkit/components/telemetry/tests/utils/TelemetryTestUtils.jsm
+++ b/toolkit/components/telemetry/tests/utils/TelemetryTestUtils.jsm
@@ -127,25 +127,28 @@ var TelemetryTestUtils = {
    * other indexes are all zero.
    *
    * @param {Object} histogram The histogram to check.
    * @param {Number} index The index to check against the expected value.
    * @param {Number} expected The expected value of the index.
    */
   assertHistogram(histogram, index, expected) {
     const snapshot = histogram.snapshot();
+    let found = false;
     for (let [i, val] of Object.entries(snapshot.values)) {
       if (i == index) {
+        found = true;
         Assert.equal(val, expected,
           `expected counts should match for the histogram index ${i}`);
       } else {
         Assert.equal(val, 0,
           `unexpected counts should be zero for the histogram index ${i}`);
       }
     }
+    Assert.ok(found, `Should have found an entry for histogram index ${index}`);
   },
 
   /**
    * Assert that a key within a keyed histogram contains the required sum.
    *
    * @param {Object} histogram The keyed histogram to check.
    * @param {String} key The key to check.
    * @param {Number} [expected] The expected sum for the key.
@@ -167,16 +170,20 @@ var TelemetryTestUtils = {
    *
    * @param {Object} histogram The keyed histogram to check.
    * @param {String} key The key to check.
    * @param {Number} index The index to check against the expected value.
    * @param {Number} [expected] The expected values for the key.
    */
   assertKeyedHistogramValue(histogram, key, index, expected) {
     const snapshot = histogram.snapshot();
+    if (!(key in snapshot)) {
+      Assert.ok(false, `The histogram must contain ${key}`);
+      return;
+    }
     for (let [i, val] of Object.entries(snapshot[key].values)) {
       if (i == index) {
         Assert.equal(val, expected,
           `expected counts should match for the histogram index ${i}`);
       } else {
         Assert.equal(val, 0,
           `unexpected counts should be zero for the histogram index ${i}`);
       }