Skip to content

Commit 9b7f583

Browse files
committed
Add test to verify that events database is initialized at the right time
1 parent 8c3ce67 commit 9b7f583

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

glean/tests/unit/core/glean.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import Plugin from "../../../src/plugins";
1919
import { Lifetime } from "../../../src/core/metrics/lifetime";
2020
import { Context } from "../../../src/core/context";
2121
import { DispatcherState } from "../../../src/core/dispatcher";
22+
import EventMetricType from "../../../src/core/metrics/types/event";
23+
import { getGleanRestartedEventMetric } from "../../../src/core/metrics/events_database";
2224

2325
class MockPlugin extends Plugin<typeof CoreEvents["afterPingCollection"]> {
2426
constructor() {
@@ -546,4 +548,28 @@ describe("Glean", function() {
546548
assert.strictEqual(postSpy.callCount, 1);
547549
assert.ok(postSpy.getCall(0).args[0].indexOf(DELETION_REQUEST_PING_NAME) !== -1);
548550
});
551+
552+
it("events database is initialized at a time when metrics can already be recorded", async function() {
553+
const event = new EventMetricType({
554+
category: "test",
555+
name: "event",
556+
sendInPings: ["custom"],
557+
lifetime: Lifetime.Ping,
558+
disabled: false
559+
});
560+
561+
// Record this event, so that when we re-initialize the events database
562+
// it will record a glean.restarted event on the `custom` ping events list.
563+
event.record();
564+
565+
await Glean.testResetGlean(testAppId, true, undefined, false);
566+
567+
// Check that Glean was able to record the `glean.restarted` event on initialization.
568+
const restartedEvent = getGleanRestartedEventMetric(["custom"]);
569+
console.log(await restartedEvent.testGetValue("custom"));
570+
// We expect two events. One that was recorded when we recorded an event on the custom ping
571+
// for the first time and another once we re-initialized.
572+
assert.strictEqual((await restartedEvent.testGetValue("custom"))?.length, 2);
573+
574+
});
549575
});

0 commit comments

Comments
 (0)