File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,9 @@ export class AsyncQueue {
206
206
// visible for testing
207
207
failure : Error | null = null ;
208
208
209
+ // Number of unexecuted operations remaining on the AsyncQueue.
210
+ private operationsCount = 0 ;
211
+
209
212
// Flag set while there's an outstanding AsyncQueue operation, used for
210
213
// assertion sanity-checks.
211
214
private operationInProgress = false ;
@@ -219,6 +222,11 @@ export class AsyncQueue {
219
222
return this . _isShuttingDown ;
220
223
}
221
224
225
+ // Visible for testing
226
+ isEmpty ( ) : boolean {
227
+ return this . operationsCount === 0 ;
228
+ }
229
+
222
230
/**
223
231
* Adds a new operation to the queue without waiting for it to complete (i.e.
224
232
* we ignore the Promise result).
@@ -280,6 +288,7 @@ export class AsyncQueue {
280
288
}
281
289
282
290
private enqueueInternal < T extends unknown > ( op : ( ) => Promise < T > ) : Promise < T > {
291
+ this . operationsCount += 1 ;
283
292
const newTail = this . tail . then ( ( ) => {
284
293
this . operationInProgress = true ;
285
294
return op ( )
@@ -305,6 +314,7 @@ export class AsyncQueue {
305
314
} )
306
315
. then ( result => {
307
316
this . operationInProgress = false ;
317
+ this . operationsCount -= 1 ;
308
318
return result ;
309
319
} ) ;
310
320
} ) ;
Original file line number Diff line number Diff line change @@ -549,6 +549,16 @@ abstract class TestRunner {
549
549
async run ( step : SpecStep ) : Promise < void > {
550
550
await this . doStep ( step ) ;
551
551
await this . queue . drain ( ) ;
552
+ // Wait for any additional operations that the initial operations
553
+ // scheduled. We skip this iterative drain for steps that involve changing
554
+ // the primary tab since tabs that become the primary can schedule
555
+ // multiple operations onto the queue that subsequent steps require.
556
+ while (
557
+ step . applyClientState ?. primary === undefined &&
558
+ ! this . queue . isEmpty ( )
559
+ ) {
560
+ await this . queue . drain ( ) ;
561
+ }
552
562
this . validateExpectedSnapshotEvents ( step . expectedSnapshotEvents ! ) ;
553
563
await this . validateExpectedState ( step . expectedState ! ) ;
554
564
this . validateSnapshotsInSyncEvents ( step . expectedSnapshotsInSyncEvents ) ;
You can’t perform that action at this time.
0 commit comments