@@ -7,20 +7,29 @@ import type { SinonFakeTimers } from "sinon";
77import sinon from "sinon" ;
88
99import { Lifetime } from "../../../../src/core/metrics/lifetime" ;
10- import EventsDatabase , { getGleanRestartedEventMetric } from "../../../../src/core/metrics/events_database" ;
11- import { InternalEventMetricType as EventMetricType } from "../../../../src/core/metrics/types/event" ;
10+ import EventsDatabase , {
11+ getGleanRestartedEventMetric ,
12+ } from "../../../../src/core/metrics/events_database" ;
13+ import { InternalEventMetricType as EventMetricType } from "../../../../src/core/metrics/types/event" ;
1214import type { JSONObject } from "../../../../src/core/utils" ;
1315import CounterMetricType from "../../../../src/core/metrics/types/counter" ;
1416import { generateReservedMetricIdentifiers } from "../../../../src/core/metrics/database" ;
15- import { InternalPingType as PingType } from "../../../../src/core/pings/ping_type" ;
17+ import { InternalPingType as PingType } from "../../../../src/core/pings/ping_type" ;
1618import { Context } from "../../../../src/core/context" ;
1719import { RecordedEvent } from "../../../../src/core/metrics/events_database/recorded_event" ;
18- import { EVENTS_PING_NAME , GLEAN_EXECUTION_COUNTER_EXTRA_KEY } from "../../../../src/core/constants" ;
20+ import {
21+ EVENTS_PING_NAME ,
22+ GLEAN_EXECUTION_COUNTER_EXTRA_KEY ,
23+ } from "../../../../src/core/constants" ;
1924import { collectPing } from "../../../../src/core/pings/maker" ;
2025import { ErrorType } from "../../../../src/core/error/error_type" ;
2126import { testResetGlean } from "../../../../src/core/testing" ;
2227import type { Event } from "../../../../src/core/metrics/events_database/recorded_event" ;
23- import { testInitializeGlean , testUninitializeGlean } from "../../../../src/core/testing/utils" ;
28+ import {
29+ testInitializeGlean ,
30+ testRestartGlean ,
31+ testUninitializeGlean ,
32+ } from "../../../../src/core/testing/utils" ;
2433import { WaitableUploader } from "../../../utils" ;
2534import type { PingPayload } from "../../../../src/core/pings/ping_payload" ;
2635
@@ -334,10 +343,7 @@ describe("EventsDatabase", function() {
334343 } ) ) ;
335344
336345 // Move the clock forward by one minute to look like Glean was really restarted.
337- Context . startTime . setTime ( Context . startTime . getTime ( ) + 1000 * 60 ) ;
338- // Fake a re-start.
339- const db2 = new EventsDatabase ( ) ;
340- await db2 . initialize ( ) ;
346+ const db2 = await testRestartGlean ( ) ;
341347
342348 for ( const store of stores ) {
343349 const snapshot = await db2 . getPingEvents ( store , true ) ;
@@ -373,10 +379,7 @@ describe("EventsDatabase", function() {
373379 } ) ) ;
374380
375381 // Move the clock forward by one minute.
376- Context . startTime . setTime ( Context . startTime . getTime ( ) + 1000 * 60 ) ;
377- // Fake a re-start.
378- db = new EventsDatabase ( ) ;
379- await db . initialize ( ) ;
382+ db = await testRestartGlean ( ) ;
380383 }
381384
382385 const snapshot = await db . getPingEvents ( "store" , true ) ;
@@ -577,10 +580,7 @@ describe("EventsDatabase", function() {
577580
578581 // Move the clock forward by one hour.
579582 const restartedTimeOffset = 1000 * 60 * 60 ;
580- Context . startTime . setTime ( firstStartTime . getTime ( ) + restartedTimeOffset ) ;
581- // Product is rebooted.
582- db = new EventsDatabase ( ) ;
583- await db . initialize ( ) ;
583+ db = await testRestartGlean ( restartedTimeOffset ) ;
584584
585585 // New events are recorded.
586586 await db . record ( event , new RecordedEvent ( {
@@ -647,10 +647,7 @@ describe("EventsDatabase", function() {
647647
648648 // Move the clock forward by one hour.
649649 const restartedTimeOffset = 1000 * 60 * 60 ;
650- Context . startTime . setTime ( firstStartTime . getTime ( ) + restartedTimeOffset ) ;
651- // Product is rebooted.
652- db = new EventsDatabase ( ) ;
653- await db . initialize ( ) ;
650+ db = await testRestartGlean ( restartedTimeOffset ) ;
654651
655652 // New set of events are recorded
656653 await db . record ( event , new RecordedEvent ( {
@@ -665,10 +662,7 @@ describe("EventsDatabase", function() {
665662 } ) ) ;
666663
667664 // Move the clock forward by one more hour.
668- Context . startTime . setTime ( firstStartTime . getTime ( ) + restartedTimeOffset * 2 ) ;
669- // Product is rebooted.
670- db = new EventsDatabase ( ) ;
671- await db . initialize ( ) ;
665+ db = await testRestartGlean ( restartedTimeOffset ) ;
672666
673667 // New set of events are recorded
674668 await db . record ( event , new RecordedEvent ( {
0 commit comments