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 458959 53d7d4732ab9
parent 458958 324d25d3f933
child 458960 ba60c53e2606
push id35552
push usershindli@mozilla.com
push dateThu, 14 Feb 2019 04:39:44 +0000
treeherdermozilla-central@c6829642e2d0 [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}`);
       }