bug 1482466 - Ensure subsession activeTicks are correct in simpleMeasurements r=Dexter a=lizzard
authorChris H-C <chutten@mozilla.com>
Tue, 14 Aug 2018 12:23:49 +0000
changeset 480953 a8ec1cd112b308528ecce3680658855d55dd4884
parent 480952 b1e62bab89ae0d96682298588f270867954136ff
child 480954 534420d993a5494bbc31cb8687928fff3f444fe9
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter, lizzard
bugs1482466
milestone62.0
bug 1482466 - Ensure subsession activeTicks are correct in simpleMeasurements r=Dexter a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D3128
toolkit/components/telemetry/TelemetrySession.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
--- a/toolkit/components/telemetry/TelemetrySession.jsm
+++ b/toolkit/components/telemetry/TelemetrySession.jsm
@@ -796,17 +796,17 @@ var Impl = {
     ret.savedPings = TelemetryStorage.pendingPingCount;
 
     let activeTicks = this._sessionActiveTicks;
     if (isSubsession) {
       activeTicks = this._sessionActiveTicks - this._subsessionStartActiveTicks;
     }
 
     if (clearSubsession) {
-      this._subsessionStartActiveTicks = activeTicks;
+      this._subsessionStartActiveTicks = this._sessionActiveTicks;
     }
 
     ret.activeTicks = activeTicks;
 
     ret.pingsOverdue = TelemetrySend.overduePingsCount;
 
     return ret;
   },
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession_activeTicks.js
@@ -1,15 +1,36 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 
 ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", this);
 ChromeUtils.import("resource://gre/modules/TelemetrySession.jsm", this);
 
+function tick(aHowMany) {
+  for (let i = 0; i < aHowMany; i++) {
+    Services.obs.notifyObservers(null, "user-interaction-active");
+  }
+}
+
+function checkSessionTicks(aExpected) {
+  let payload = TelemetrySession.getPayload();
+  Assert.equal(payload.simpleMeasurements.activeTicks, aExpected,
+               "Should record the expected number of active ticks for the session.");
+}
+
+function checkSubsessionTicks(aExpected, aClearSubsession) {
+  let payload = TelemetrySession.getPayload("main", aClearSubsession);
+  Assert.equal(payload.simpleMeasurements.activeTicks, aExpected,
+               "Should record the expected number of active ticks for the subsession.");
+  if (aExpected > 0) {
+    Assert.equal(payload.processes.parent.scalars["browser.engagement.active_ticks"], aExpected,
+                 "Should record the expected number of active ticks for the subsession, in a scalar.");
+  }
+}
 
 add_task(async function test_setup() {
   do_get_profile();
   // Make sure we don't generate unexpected pings due to pref changes.
   await setEmptyPrefWatchlist();
 });
 
 add_task(async function test_record_activeTicks() {
@@ -44,8 +65,38 @@ add_task(async function test_record_acti
   Services.obs.notifyObservers(null, "user-interaction-active");
   checkActiveTicks(4);
 
   Services.obs.notifyObservers(null, "user-interaction-active");
   checkActiveTicks(5);
 
   await TelemetryController.testShutdown();
 });
+
+add_task({
+  skip_if: () => gIsAndroid
+},
+async function test_subsession_activeTicks() {
+  await TelemetryController.testReset();
+  Telemetry.clearScalars();
+
+  tick(5);
+  checkSessionTicks(5);
+  checkSubsessionTicks(5, true);
+
+  // After clearing the subsession, subsession ticks should be 0 but session
+  // ticks should still be 5.
+  checkSubsessionTicks(0);
+  checkSessionTicks(5);
+
+  tick(1);
+  checkSessionTicks(6);
+  checkSubsessionTicks(1, true);
+
+  checkSubsessionTicks(0);
+  checkSessionTicks(6);
+
+  tick(2);
+  checkSessionTicks(8);
+  checkSubsessionTicks(2);
+
+  await TelemetryController.testShutdown();
+});