Bug 1498166 - Test storing into multiple stores (and snapshotting main store) r=chutten
authorJan-Erik Rediger <jrediger@mozilla.com>
Mon, 19 Nov 2018 13:01:05 +0000
changeset 503884 ed977fa7caf89d0cff04c3f270124972c433c908
parent 503883 544d3ecf27ab29902f07237a3170b1c8217672a7
child 503885 67ae9d05389679fed9f5f3b1a681402c719a90f7
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1498166
milestone65.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 1498166 - Test storing into multiple stores (and snapshotting main store) r=chutten For now we test that storing still works and the main store is still accessed for snapshots and clearing. Depends on D11906 Differential Revision: https://phabricator.services.mozilla.com/D11907
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7796,16 +7796,42 @@
     "kind": "linear",
     "low": 1,
     "high": 2147483646,
     "n_buckets": 10,
     "bug_numbers": [1498164],
     "description": "a testing histogram; not meant to be touched",
     "record_into_store": ["main", "sync"]
   },
+  "TELEMETRY_TEST_KEYED_SYNC_ONLY": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "linear",
+    "keyed": true,
+    "low": 1,
+    "high": 2147483646,
+    "n_buckets": 10,
+    "bug_numbers": [1498164],
+    "description": "a testing histogram; not meant to be touched",
+    "record_into_store": ["sync"]
+  },
+  "TELEMETRY_TEST_KEYED_MULTIPLE_STORES": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "linear",
+    "keyed": true,
+    "low": 1,
+    "high": 2147483646,
+    "n_buckets": 10,
+    "bug_numbers": [1498164],
+    "description": "a testing histogram; not meant to be touched",
+    "record_into_store": ["main", "sync"]
+  },
   "STARTUP_CRASH_DETECTED": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Whether there was a crash during the last startup"
   },
   "SAFE_MODE_USAGE": {
     "record_in_processes": ["main", "content"],
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
@@ -1178,8 +1178,142 @@ add_task(async function test_valid_os_sm
   let h = Telemetry.getHistogramById(existingProbe);
   h.clear();
   h.add(1);
   let snapshot = Telemetry.getSnapshotForHistograms("main",
                                               false /* clear */).parent;
   Assert.ok(existingProbe in snapshot, `${existingProbe} should be recorded on ${AppConstants.platform}`);
   Assert.equal(snapshot[existingProbe].sum, 1);
 });
+
+add_task(async function test_multistore_individual_histogram() {
+  Telemetry.canRecordExtended = true;
+
+  let id;
+  let hist;
+  let snapshot;
+
+  id = "TELEMETRY_TEST_MAIN_ONLY";
+  hist = Telemetry.getHistogramById(id);
+  snapshot = hist.snapshot();
+  Assert.equal(0, snapshot.sum, `Histogram ${id} should be empty.`);
+  hist.add(1);
+  snapshot = hist.snapshot();
+  Assert.equal(1, snapshot.sum, `Histogram ${id} should have recorded one value.`);
+  hist.clear();
+  snapshot = hist.snapshot();
+  Assert.equal(0, snapshot.sum, `Histogram ${id} should be cleared.`);
+
+  id = "TELEMETRY_TEST_MULTIPLE_STORES";
+  hist = Telemetry.getHistogramById(id);
+  snapshot = hist.snapshot();
+  Assert.equal(0, snapshot.sum, `Histogram ${id} should be empty.`);
+  hist.add(1);
+  snapshot = hist.snapshot();
+  Assert.equal(1, snapshot.sum, `Histogram ${id} should have recorded one value.`);
+  hist.clear();
+  snapshot = hist.snapshot();
+  Assert.equal(0, snapshot.sum, `Histogram ${id} should be cleared.`);
+
+  // When sync only, then the snapshot will be empty on the main store
+  id = "TELEMETRY_TEST_SYNC_ONLY";
+  hist = Telemetry.getHistogramById(id);
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+  hist.add(1);
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+  hist.clear();
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+
+  id = "TELEMETRY_TEST_KEYED_MULTIPLE_STORES";
+  hist = Telemetry.getKeyedHistogramById(id);
+  snapshot = hist.snapshot();
+  Assert.deepEqual({}, snapshot, `Histogram ${id} should be empty.`);
+  hist.add("key-a", 1);
+  snapshot = hist.snapshot();
+  Assert.equal(1, snapshot["key-a"].sum, `Histogram ${id} should have recorded one value.`);
+  hist.clear();
+  snapshot = hist.snapshot();
+  Assert.deepEqual({}, snapshot, `Histogram ${id} should be cleared.`);
+
+  // When sync only, then the snapshot will be empty on the main store
+  id = "TELEMETRY_TEST_KEYED_SYNC_ONLY";
+  hist = Telemetry.getKeyedHistogramById(id);
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+  hist.add("key-a", 1);
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+  hist.clear();
+  snapshot = hist.snapshot();
+  Assert.equal(undefined, snapshot, `Histogram ${id} should not be in the 'main' storage`);
+});
+
+add_task(async function test_multistore_main_snapshot() {
+  Telemetry.canRecordExtended = true;
+  // Clear histograms
+  Telemetry.getSnapshotForHistograms("main", true);
+  Telemetry.getSnapshotForKeyedHistograms("main", true);
+
+  let id;
+  let hist;
+  let snapshot;
+
+  // Plain histograms
+
+  // Fill with data
+  id = "TELEMETRY_TEST_MAIN_ONLY";
+  hist = Telemetry.getHistogramById(id);
+  hist.add(1);
+
+  id = "TELEMETRY_TEST_MULTIPLE_STORES";
+  hist = Telemetry.getHistogramById(id);
+  hist.add(1);
+
+  id = "TELEMETRY_TEST_SYNC_ONLY";
+  hist = Telemetry.getHistogramById(id);
+  hist.add(1);
+
+  // Getting snapshot and clearing
+  snapshot = Telemetry.getSnapshotForHistograms("main", /* clear */ true).parent;
+  id = "TELEMETRY_TEST_MAIN_ONLY";
+  Assert.ok(id in snapshot, `${id} should be in a main store snapshot`);
+  id = "TELEMETRY_TEST_MULTIPLE_STORES";
+  Assert.ok(id in snapshot, `${id} should be in a main store snapshot`);
+  id = "TELEMETRY_TEST_SYNC_ONLY";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+
+  // Should be empty after clearing
+  snapshot = Telemetry.getSnapshotForHistograms("main", /* clear */ false).parent;
+  id = "TELEMETRY_TEST_MAIN_ONLY";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+  id = "TELEMETRY_TEST_MULTIPLE_STORES";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+  id = "TELEMETRY_TEST_SYNC_ONLY";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+
+  // Keyed histograms
+
+  // Fill with data
+  id = "TELEMETRY_TEST_KEYED_MULTIPLE_STORES";
+  hist = Telemetry.getKeyedHistogramById(id);
+  hist.add("key-a", 1);
+
+  id = "TELEMETRY_TEST_KEYED_SYNC_ONLY";
+  hist = Telemetry.getKeyedHistogramById(id);
+  hist.add("key-b", 1);
+
+  // Getting snapshot and clearing
+  snapshot = Telemetry.getSnapshotForKeyedHistograms("main", /* clear */ true).parent;
+  id = "TELEMETRY_TEST_KEYED_MULTIPLE_STORES";
+  Assert.ok(id in snapshot, `${id} should be in a main store snapshot`);
+  id = "TELEMETRY_TEST_KEYED_SYNC_ONLY";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+
+  // Should be empty after clearing
+  snapshot = Telemetry.getSnapshotForKeyedHistograms("main", /* clear */ false).parent;
+  id = "TELEMETRY_TEST_KEYED_MULTIPLE_STORES";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+  id = "TELEMETRY_TEST_KEYED_SYNC_ONLY";
+  Assert.ok(!(id in snapshot), `${id} should not be in a main store snapshot`);
+});