@@ -141,13 +141,6 @@ class MockConnection implements Connection {
141
141
/** A Deferred that is resolved once watch opens. */
142
142
watchOpen = new Deferred < void > ( ) ;
143
143
144
- reset ( ) : void {
145
- this . watchStreamRequestCount = 0 ;
146
- this . writeStreamRequestCount = 0 ;
147
- this . earlyWrites = [ ] ;
148
- this . activeTargets = [ ] ;
149
- }
150
-
151
144
invokeRPC < Req > ( rpcName : string , request : Req ) : never {
152
145
throw new Error ( 'Not implemented!' ) ;
153
146
}
@@ -399,23 +392,29 @@ abstract class TestRunner {
399
392
'host' ,
400
393
false
401
394
) ;
395
+
396
+ // TODO(mrschmidt): During client startup in `firestore_client`, we block
397
+ // the AsyncQueue from executing any operation. We should mimic this in the
398
+ // setup of the spec tests.
402
399
this . queue = new AsyncQueue ( ) ;
403
400
this . serializer = new JsonProtoSerializer ( this . databaseInfo . databaseId , {
404
401
useProto3Json : true
405
402
} ) ;
406
- this . persistence = this . getPersistence ( this . serializer ) ;
407
403
408
404
this . useGarbageCollection = config . useGarbageCollection ;
409
405
410
- this . init ( ) ;
411
-
412
406
this . expectedLimboDocs = [ ] ;
413
407
this . expectedActiveTargets = { } ;
414
408
this . acknowledgedDocs = [ ] ;
415
409
this . rejectedDocs = [ ] ;
416
410
}
417
411
418
- private init ( ) : void {
412
+ async start ( ) : Promise < void > {
413
+ this . persistence = await this . initPersistence ( this . serializer ) ;
414
+ await this . init ( ) ;
415
+ }
416
+
417
+ private async init ( ) : Promise < void > {
419
418
const garbageCollector = this . getGarbageCollector ( ) ;
420
419
421
420
this . sharedClientState = this . getSharedClientState ( ) ;
@@ -466,6 +465,16 @@ abstract class TestRunner {
466
465
this . sharedClientState . onlineStateHandler = sharedClientStateOnlineStateChangedHandler ;
467
466
468
467
this . eventManager = new EventManager ( this . syncEngine ) ;
468
+
469
+ await this . localStore . start ( ) ;
470
+ await this . sharedClientState . start ( ) ;
471
+ await this . remoteStore . start ( ) ;
472
+
473
+ await this . persistence . setPrimaryStateListener ( isPrimary =>
474
+ this . syncEngine . applyPrimaryState ( isPrimary )
475
+ ) ;
476
+
477
+ this . started = true ;
469
478
}
470
479
471
480
private getGarbageCollector ( ) : GarbageCollector {
@@ -474,32 +483,16 @@ abstract class TestRunner {
474
483
: new NoOpGarbageCollector ( ) ;
475
484
}
476
485
477
- protected abstract getPersistence (
486
+ protected abstract initPersistence (
478
487
serializer : JsonProtoSerializer
479
- ) : Persistence ;
480
-
481
- protected abstract startPersistence ( persistence : Persistence ) : Promise < void > ;
488
+ ) : Promise < Persistence > ;
482
489
483
490
protected abstract getSharedClientState ( ) : SharedClientState ;
484
491
485
492
get isPrimaryClient ( ) : boolean {
486
493
return this . syncEngine . isPrimaryClient ;
487
494
}
488
495
489
- async start ( ) : Promise < void > {
490
- this . connection . reset ( ) ;
491
- await this . startPersistence ( this . persistence ) ;
492
- await this . localStore . start ( ) ;
493
- await this . sharedClientState . start ( ) ;
494
- await this . remoteStore . start ( ) ;
495
-
496
- await this . persistence . setPrimaryStateListener ( isPrimary =>
497
- this . syncEngine . applyPrimaryState ( isPrimary )
498
- ) ;
499
-
500
- this . started = true ;
501
- }
502
-
503
496
async shutdown ( ) : Promise < void > {
504
497
if ( this . started ) {
505
498
await this . doShutdown ( ) ;
@@ -874,19 +867,9 @@ abstract class TestRunner {
874
867
// No local store to shutdown.
875
868
await this . remoteStore . shutdown ( ) ;
876
869
877
- this . init ( ) ;
878
-
879
870
// We have to schedule the starts, otherwise we could end up with
880
871
// interleaved events.
881
- await this . queue . enqueue ( async ( ) => {
882
- await this . localStore . start ( ) ;
883
- await this . remoteStore . start ( ) ;
884
- await this . sharedClientState . start ( ) ;
885
-
886
- await this . persistence . setPrimaryStateListener ( isPrimary =>
887
- this . syncEngine . applyPrimaryState ( isPrimary )
888
- ) ;
889
- } ) ;
872
+ await this . queue . enqueue ( ( ) => this . init ( ) ) ;
890
873
}
891
874
892
875
private async doApplyClientState ( state : SpecClientState ) : Promise < void > {
@@ -1142,16 +1125,16 @@ abstract class TestRunner {
1142
1125
}
1143
1126
1144
1127
class MemoryTestRunner extends TestRunner {
1145
- protected getPersistence ( serializer : JsonProtoSerializer ) : Persistence {
1146
- return new MemoryPersistence ( this . clientId ) ;
1147
- }
1148
-
1149
1128
protected getSharedClientState ( ) : SharedClientState {
1150
1129
return new MemorySharedClientState ( ) ;
1151
1130
}
1152
1131
1153
- protected startPersistence ( persistence : Persistence ) : Promise < void > {
1154
- return persistence . start ( ) ;
1132
+ protected async initPersistence (
1133
+ serializer : JsonProtoSerializer
1134
+ ) : Promise < Persistence > {
1135
+ const persistence = new MemoryPersistence ( this . clientId ) ;
1136
+ await persistence . start ( ) ;
1137
+ return persistence ;
1155
1138
}
1156
1139
}
1157
1140
@@ -1162,16 +1145,6 @@ class MemoryTestRunner extends TestRunner {
1162
1145
class IndexedDbTestRunner extends TestRunner {
1163
1146
static TEST_DB_NAME = 'firestore/[DEFAULT]/specs' ;
1164
1147
1165
- protected getPersistence ( serializer : JsonProtoSerializer ) : Persistence {
1166
- return new IndexedDbPersistence (
1167
- IndexedDbTestRunner . TEST_DB_NAME ,
1168
- this . clientId ,
1169
- this . platform ,
1170
- this . queue ,
1171
- serializer
1172
- ) ;
1173
- }
1174
-
1175
1148
protected getSharedClientState ( ) : SharedClientState {
1176
1149
return new WebStorageSharedClientState (
1177
1150
this . queue ,
@@ -1182,10 +1155,18 @@ class IndexedDbTestRunner extends TestRunner {
1182
1155
) ;
1183
1156
}
1184
1157
1185
- protected startPersistence ( persistence : Persistence ) : Promise < void > {
1186
- return ( persistence as IndexedDbPersistence ) . start (
1187
- /*synchronizeTabs=*/ true
1158
+ protected async initPersistence (
1159
+ serializer : JsonProtoSerializer
1160
+ ) : Promise < Persistence > {
1161
+ const persistence = new IndexedDbPersistence (
1162
+ IndexedDbTestRunner . TEST_DB_NAME ,
1163
+ this . clientId ,
1164
+ this . platform ,
1165
+ this . queue ,
1166
+ serializer
1188
1167
) ;
1168
+ await persistence . start ( /*synchronizeTabs=*/ true ) ;
1169
+ return persistence ;
1189
1170
}
1190
1171
1191
1172
static destroyPersistence ( ) : Promise < void > {
0 commit comments