@@ -550,7 +550,7 @@ describe('BulkWriter', () => {
550
550
describe ( '500/50/5 support' , ( ) => {
551
551
afterEach ( ( ) => setTimeoutHandler ( setTimeout ) ) ;
552
552
553
- it ( 'does not send batches if doing so exceeds the rate limit' , done => {
553
+ it ( 'does not send batches if doing so exceeds the rate limit' , async ( ) => {
554
554
// The test is considered a success if BulkWriter tries to send the second
555
555
// batch again after a timeout.
556
556
@@ -561,7 +561,7 @@ describe('BulkWriter', () => {
561
561
const requests2 = arrayRange2 . map ( i => setOp ( 'doc' + i , 'bar' ) ) ;
562
562
const responses2 = arrayRange2 . map ( i => successResponse ( i ) ) ;
563
563
564
- instantiateInstance ( [
564
+ const bulkWriter = await instantiateInstance ( [
565
565
{
566
566
request : createRequest ( requests1 ) ,
567
567
response : mergeResponses ( responses1 ) ,
@@ -570,33 +570,34 @@ describe('BulkWriter', () => {
570
570
request : createRequest ( requests2 ) ,
571
571
response : mergeResponses ( responses2 ) ,
572
572
} ,
573
- ] ) . then ( bulkWriter => {
574
- setTimeoutHandler ( ( ) =>
575
- done ( new Error ( 'This batch should not have a timeout' ) )
576
- ) ;
577
- for ( let i = 0 ; i < 500 ; i ++ ) {
578
- bulkWriter
579
- . set ( firestore . doc ( 'collectionId/doc' + i ) , { foo : 'bar' } )
580
- . then ( incrementOpCount ) ;
581
- }
582
- bulkWriter . flush ( ) ;
583
-
584
- // Sending this next batch would go over the 500/50/5 capacity, so
585
- // check that BulkWriter doesn't send this batch until the first batch
586
- // is resolved.
587
- setTimeoutHandler ( ( _ , timeout ) => {
588
- // Check that BulkWriter has not yet sent the 2nd batch.
589
- expect ( requestCounter ) . to . equal ( 0 ) ;
590
- expect ( timeout ) . to . be . greaterThan ( 0 ) ;
591
- done ( ) ;
592
- } ) ;
593
- for ( let i = 500 ; i < 505 ; i ++ ) {
594
- bulkWriter
595
- . set ( firestore . doc ( 'collectionId/doc' + i ) , { foo : 'bar' } )
596
- . then ( incrementOpCount ) ;
597
- }
598
- return bulkWriter . flush ( ) ;
573
+ ] ) ;
574
+ for ( let i = 0 ; i < 500 ; i ++ ) {
575
+ bulkWriter
576
+ . set ( firestore . doc ( 'collectionId/doc' + i ) , { foo : 'bar' } )
577
+ . then ( incrementOpCount ) ;
578
+ }
579
+ const flush1 = bulkWriter . flush ( ) ;
580
+
581
+ // Sending this next batch would go over the 500/50/5 capacity, so
582
+ // check that BulkWriter doesn't send this batch until the first batch
583
+ // is resolved.
584
+ let timeoutCalled = false ;
585
+ setTimeoutHandler ( ( _ , timeout ) => {
586
+ // Check that BulkWriter has not yet sent the 2nd batch.
587
+ timeoutCalled = true ;
588
+ expect ( requestCounter ) . to . equal ( 0 ) ;
589
+ expect ( timeout ) . to . be . greaterThan ( 0 ) ;
599
590
} ) ;
591
+ for ( let i = 500 ; i < 505 ; i ++ ) {
592
+ bulkWriter
593
+ . set ( firestore . doc ( 'collectionId/doc' + i ) , { foo : 'bar' } )
594
+ . then ( incrementOpCount ) ;
595
+ }
596
+ const flush2 = bulkWriter . flush ( ) ;
597
+ await flush1 ;
598
+ await flush2 ;
599
+ expect ( timeoutCalled ) . to . be . true ;
600
+ return bulkWriter . close ( ) ;
600
601
} ) ;
601
602
} ) ;
602
603
0 commit comments