@@ -48,9 +48,10 @@ describe("PingsDatabase", function() {
4848 let wasNotified = false ;
4949 const identifier = "THE IDENTIFIER" ;
5050 const observer : Observer = {
51- update : ( id : string ) : void = > {
51+ async update ( id : string ) : Promise < string [ ] > {
5252 wasNotified = true ;
5353 assert . strictEqual ( id , identifier ) ;
54+ return [ ] ;
5455 }
5556 } ;
5657
@@ -234,4 +235,51 @@ describe("PingsDatabase", function() {
234235 assert . strictEqual ( Object . keys ( await db [ "store" ] . _getWholeStore ( ) ) . length , 0 ) ;
235236 } ) ;
236237 } ) ;
238+
239+ describe ( "pending pings" , function ( ) {
240+ it ( "scanning the pending pings directory fills up the queue" , async function ( ) {
241+ let resolver : ( value : unknown ) => void ;
242+ let testPromise = new Promise ( r => resolver = r ) ;
243+ let pingIds : string [ ] = [ ] ;
244+ const observer : Observer = {
245+ async update ( id : string ) : Promise < string [ ] > {
246+ pingIds . push ( id ) ;
247+
248+ if ( pingIds . length == 10 ) {
249+ resolver ( pingIds ) ;
250+ }
251+ return [ ] ;
252+ }
253+ } ;
254+ const db = new Database ( Glean . platform . Storage , observer ) ;
255+
256+ const path = "some/random/path/doesnt/matter" ;
257+ const payload = {
258+ ping_info : {
259+ seq : 1 ,
260+ start_time : "2018-02-24+01:00" ,
261+ end_time : "2018-02-25+11:00" ,
262+ } ,
263+ client_info : {
264+ telemetry_sdk_build : "32.0.0"
265+ }
266+ } ;
267+
268+ for ( let id = 0 ; id < 10 ; id ++ ) {
269+ let newPayload = payload ;
270+ newPayload . ping_info . seq = id ;
271+ await db . recordPing ( path , `id-${ id } ` , payload ) ;
272+ }
273+
274+ // Reset the ids we've seen because `Observer` will get called once again in `record`.
275+ pingIds = [ ] ;
276+
277+ await db . scanPendingPings ( ) ;
278+ await testPromise ;
279+ assert . strictEqual ( pingIds . length , 10 ) ;
280+ for ( let id = 0 ; id < 10 ; id ++ ) {
281+ assert . ok ( id in pingIds ) ;
282+ }
283+ } ) ;
284+ } ) ;
237285} ) ;
0 commit comments