Skip to content

Commit

Permalink
Attend to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brizental committed Apr 27, 2021
1 parent c67364e commit 4dbef01
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.10.2...main)

* [#202](https://github.com/mozilla/glean.js/pull/202): Add a testing API for the ping type.
* [#253](https://github.com/mozilla/glean.js/pull/253): Implement the timespan metric type.

# v0.10.2 (2021-04-26)

Expand Down
6 changes: 5 additions & 1 deletion glean/src/core/metrics/types/timespan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ class TimespanMetricType extends MetricType {
* No error is recorded if no `start()` was called.
*/
cancel(): void {
this.startTime = undefined;
Context.dispatcher.launch(() => {
this.startTime = undefined;
return Promise.resolve();
});
}

/**
Expand All @@ -190,6 +193,7 @@ class TimespanMetricType extends MetricType {
});

if (value) {
// `payload` will truncate to the defined time_unit at the time of recording.
return (new TimespanMetric(value)).payload();
}
}
Expand Down
3 changes: 2 additions & 1 deletion glean/tests/core/metrics/timespan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe("TimespanMetric", function() {
assert.deepStrictEqual(consoleErrorSpy.callCount, 1);
});

it("cancel does not store", async function() {
it("cancel does not store and clears start time", async function() {
const metric = new TimespanMetricType({
category: "aCategory",
name: "aTimespan",
Expand All @@ -222,6 +222,7 @@ describe("TimespanMetric", function() {
metric.start();
metric.cancel();
assert.strictEqual(await metric.testGetValue("aPing"), undefined);
assert.strictEqual(metric["startTime"], undefined);
});

it("nothing is stored before stop", async function() {
Expand Down

0 comments on commit 4dbef01

Please sign in to comment.