@@ -384,17 +384,35 @@ test('Ingest collection failure is published to post-ingest SNS topic', async (t
384
384
t . is ( attrs . recordType . Value , 'Collection' )
385
385
} )
386
386
387
+ async function emptyPostIngestQueue ( t ) {
388
+ // We initially tried calling
389
+ // await sqs().purgeQueue({ QueueUrl: postIngestQueueUrl }).promise()
390
+ // But at least one test would intermittently fail because of an additional
391
+ // message in the queue.
392
+ // The documentation for the purgeQueue method says:
393
+ // "The message deletion process takes up to 60 seconds.
394
+ // We recommend waiting for 60 seconds regardless of your queue's size."
395
+ let result
396
+ do {
397
+ // eslint-disable-next-line no-await-in-loop
398
+ result = await sqs ( ) . receiveMessage ( {
399
+ QueueUrl : t . context . postIngestQueueUrl ,
400
+ WaitTimeSeconds : 1
401
+ } ) . promise ( )
402
+ } while ( result . Message && result . Message . length > 0 )
403
+ }
404
+
387
405
async function ingestCollectionAndPurgePostIngestQueue ( t ) {
388
- const { ingestFixture, postIngestQueueUrl } = t . context
406
+ const { ingestFixture } = t . context
389
407
390
408
const collection = await ingestFixture (
391
409
'landsat-8-l1-collection.json' ,
392
410
{ id : randomId ( 'collection' ) }
393
411
)
394
412
395
- // Purging the post-ingest queue ensures that subsequent calls to testPostIngestSNS
413
+ // Emptying the post-ingest queue ensures that subsequent calls to testPostIngestSNS
396
414
// only see the message posted after the final ingest
397
- await sqs ( ) . purgeQueue ( { QueueUrl : postIngestQueueUrl } ) . promise ( )
415
+ await emptyPostIngestQueue ( t )
398
416
399
417
return collection
400
418
}
0 commit comments