@@ -19,6 +19,8 @@ import Plugin from "../../../src/plugins";
1919import { Lifetime } from "../../../src/core/metrics/lifetime" ;
2020import { Context } from "../../../src/core/context" ;
2121import { DispatcherState } from "../../../src/core/dispatcher" ;
22+ import EventMetricType from "../../../src/core/metrics/types/event" ;
23+ import { getGleanRestartedEventMetric } from "../../../src/core/metrics/events_database" ;
2224
2325class 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