@@ -174,6 +174,9 @@ class MockConnection implements Connection {
174
174
/** A Deferred that is resolved once watch opens. */
175
175
watchOpen = new Deferred < void > ( ) ;
176
176
177
+ /** A Deferred that is resolved once the write stream opens. */
178
+ writeOpen = new Deferred < void > ( ) ;
179
+
177
180
invokeRPC < Req > ( rpcName : string , request : Req ) : never {
178
181
throw new Error ( 'Not implemented!' ) ;
179
182
}
@@ -196,6 +199,10 @@ class MockConnection implements Connection {
196
199
return this . watchOpen . promise ;
197
200
}
198
201
202
+ waitForWriteOpen ( ) : Promise < void > {
203
+ return this . writeOpen . promise ;
204
+ }
205
+
199
206
ackWrite ( commitTime ?: string , mutationResults ?: api . WriteResult [ ] ) : void {
200
207
this . writeStream ! . callOnMessage ( {
201
208
// Convert to base64 string so it can later be parsed into ByteString.
@@ -215,6 +222,7 @@ class MockConnection implements Connection {
215
222
private resetAndCloseWriteStream ( err ?: FirestoreError ) : void {
216
223
this . writeSendBarriers = [ ] ;
217
224
this . earlyWrites = [ ] ;
225
+ this . writeOpen = new Deferred < void > ( ) ;
218
226
this . writeStream ! . callOnClose ( err ) ;
219
227
this . writeStream = null ;
220
228
}
@@ -280,11 +288,16 @@ class MockConnection implements Connection {
280
288
this . resetAndCloseWriteStream ( ) ;
281
289
}
282
290
} ) ;
283
- this . queue . enqueueAndForget ( async ( ) => {
284
- if ( this . writeStream === writeStream ) {
285
- writeStream . callOnOpen ( ) ;
286
- }
287
- } ) ;
291
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
292
+ this . queue
293
+ . enqueue ( async ( ) => {
294
+ if ( this . writeStream === writeStream ) {
295
+ writeStream . callOnOpen ( ) ;
296
+ }
297
+ } )
298
+ . then ( ( ) => {
299
+ this . writeOpen . resolve ( ) ;
300
+ } ) ;
288
301
this . writeStream = writeStream ;
289
302
// Replace 'any' with conditional types.
290
303
return writeStream as any ; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -313,12 +326,16 @@ class MockConnection implements Connection {
313
326
}
314
327
} ) ;
315
328
// Call on open immediately after returning
316
- this . queue . enqueueAndForget ( async ( ) => {
317
- if ( this . watchStream === watchStream ) {
318
- watchStream . callOnOpen ( ) ;
329
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
330
+ this . queue
331
+ . enqueue ( async ( ) => {
332
+ if ( this . watchStream === watchStream ) {
333
+ watchStream . callOnOpen ( ) ;
334
+ }
335
+ } )
336
+ . then ( ( ) => {
319
337
this . watchOpen . resolve ( ) ;
320
- }
321
- } ) ;
338
+ } ) ;
322
339
this . watchStream = watchStream ;
323
340
// Replace 'any' with conditional types.
324
341
return this . watchStream as any ; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -931,6 +948,9 @@ abstract class TestRunner {
931
948
private async doEnableNetwork ( ) : Promise < void > {
932
949
this . networkEnabled = true ;
933
950
await this . syncEngine . enableNetwork ( ) ;
951
+ if ( this . connection . writeStream !== null ) {
952
+ await this . connection . waitForWriteOpen ( ) ;
953
+ }
934
954
}
935
955
936
956
private async doShutdown ( ) : Promise < void > {
0 commit comments