@@ -18,6 +18,7 @@ import TestPlatform from "../../../src/platform/test";
1818import Plugin from "../../../src/plugins" ;
1919import { Lifetime } from "../../../src/core/metrics/lifetime" ;
2020import { Context } from "../../../src/core/context" ;
21+ import { DispatcherState } from "../../../src/core/dispatcher" ;
2122
2223class MockPlugin extends Plugin < typeof CoreEvents [ "afterPingCollection" ] > {
2324 constructor ( ) {
@@ -504,4 +505,25 @@ describe("Glean", function() {
504505
505506 assert . strictEqual ( TestPlatform . name , Glean . platform . name ) ;
506507 } ) ;
508+
509+ it ( "shutdown correctly shutsdown dispatcher and ping uploader" , async function ( ) {
510+ await Glean . shutdown ( ) ;
511+ assert . strictEqual ( Context . dispatcher [ "state" ] , DispatcherState . Shutdown ) ;
512+ assert . strictEqual ( Glean [ "pingUploader" ] [ "dispatcher" ] [ "state" ] , DispatcherState . Shutdown ) ;
513+ } ) ;
514+
515+ it ( "shutdown allows all pending pings to be sent before shutting down uploader" , async function ( ) {
516+ const postSpy = sandbox . spy ( Glean . platform . uploader , "post" ) ;
517+
518+ // `setUploadEnabled` is a task dispatched on the main dispatcher,
519+ // inside this task an uploading task is dispatched to the ping uploader dispatcher.
520+ //
521+ // We want to be sure the ping uploader dispatcher is not shutdown
522+ // before it can execute this final task.
523+ Glean . setUploadEnabled ( false ) ;
524+ await Glean . shutdown ( ) ;
525+
526+ assert . strictEqual ( postSpy . callCount , 1 ) ;
527+ assert . ok ( postSpy . getCall ( 0 ) . args [ 0 ] . indexOf ( DELETION_REQUEST_PING_NAME ) !== - 1 ) ;
528+ } ) ;
507529} ) ;
0 commit comments