@@ -454,17 +454,19 @@ abstract class TestRunner {
454
454
} else if ( 'userDelete' in step ) {
455
455
return this . doDelete ( step . userDelete ! ) ;
456
456
} else if ( 'watchAck' in step ) {
457
- return this . doWatchAck ( step . watchAck ! , step . watchSnapshot ) ;
457
+ return this . doWatchAck ( step . watchAck ! ) ;
458
458
} else if ( 'watchCurrent' in step ) {
459
- return this . doWatchCurrent ( step . watchCurrent ! , step . watchSnapshot ) ;
459
+ return this . doWatchCurrent ( step . watchCurrent ! ) ;
460
460
} else if ( 'watchRemove' in step ) {
461
- return this . doWatchRemove ( step . watchRemove ! , step . watchSnapshot ) ;
461
+ return this . doWatchRemove ( step . watchRemove ! ) ;
462
462
} else if ( 'watchEntity' in step ) {
463
- return this . doWatchEntity ( step . watchEntity ! , step . watchSnapshot ) ;
463
+ return this . doWatchEntity ( step . watchEntity ! ) ;
464
464
} else if ( 'watchFilter' in step ) {
465
- return this . doWatchFilter ( step . watchFilter ! , step . watchSnapshot ) ;
465
+ return this . doWatchFilter ( step . watchFilter ! ) ;
466
+ } else if ( 'watchSnapshot' in step ) {
467
+ return this . doWatchSnapshot ( step . watchSnapshot ! ) ;
466
468
} else if ( 'watchReset' in step ) {
467
- return this . doWatchReset ( step . watchReset ! , step . watchSnapshot ) ;
469
+ return this . doWatchReset ( step . watchReset ! ) ;
468
470
} else if ( 'watchStreamClose' in step ) {
469
471
return this . doWatchStreamClose ( step . watchStreamClose ! ) ;
470
472
} else if ( 'writeAck' in step ) {
@@ -554,46 +556,34 @@ abstract class TestRunner {
554
556
} ) ;
555
557
}
556
558
557
- private doWatchAck (
558
- ackedTargets : SpecWatchAck ,
559
- watchSnapshot ?: SpecSnapshotVersion
560
- ) : Promise < void > {
559
+ private doWatchAck ( ackedTargets : SpecWatchAck ) : Promise < void > {
561
560
const change = new WatchTargetChange (
562
561
WatchTargetChangeState . Added ,
563
562
ackedTargets
564
563
) ;
565
- return this . doWatchEvent ( change , watchSnapshot ) ;
564
+ return this . doWatchEvent ( change ) ;
566
565
}
567
566
568
- private doWatchCurrent (
569
- currentTargets : SpecWatchCurrent ,
570
- watchSnapshot ?: SpecSnapshotVersion
571
- ) : Promise < void > {
567
+ private doWatchCurrent ( currentTargets : SpecWatchCurrent ) : Promise < void > {
572
568
const targets = currentTargets [ 0 ] ;
573
569
const resumeToken = currentTargets [ 1 ] as ProtoByteString ;
574
570
const change = new WatchTargetChange (
575
571
WatchTargetChangeState . Current ,
576
572
targets ,
577
573
resumeToken
578
574
) ;
579
- return this . doWatchEvent ( change , watchSnapshot ) ;
575
+ return this . doWatchEvent ( change ) ;
580
576
}
581
577
582
- private doWatchReset (
583
- targetIds : SpecWatchReset ,
584
- watchSnapshot ?: SpecSnapshotVersion
585
- ) : Promise < void > {
578
+ private doWatchReset ( targetIds : SpecWatchReset ) : Promise < void > {
586
579
const change = new WatchTargetChange (
587
580
WatchTargetChangeState . Reset ,
588
581
targetIds
589
582
) ;
590
- return this . doWatchEvent ( change , watchSnapshot ) ;
583
+ return this . doWatchEvent ( change ) ;
591
584
}
592
585
593
- private doWatchRemove (
594
- removed : SpecWatchRemove ,
595
- watchSnapshot ?: SpecSnapshotVersion
596
- ) : Promise < void > {
586
+ private doWatchRemove ( removed : SpecWatchRemove ) : Promise < void > {
597
587
const cause =
598
588
removed . cause &&
599
589
new FirestoreError (
@@ -619,30 +609,21 @@ abstract class TestRunner {
619
609
delete this . connection . activeTargets [ targetId ] ;
620
610
} ) ;
621
611
}
622
- return this . doWatchEvent ( change , watchSnapshot ) ;
612
+ return this . doWatchEvent ( change ) ;
623
613
}
624
614
625
- private doWatchEntity (
626
- watchEntity : SpecWatchEntity ,
627
- watchSnapshot ?: SpecSnapshotVersion
628
- ) : Promise < void > {
615
+ private doWatchEntity ( watchEntity : SpecWatchEntity ) : Promise < void > {
629
616
if ( watchEntity . docs ) {
630
617
assert (
631
618
! watchEntity . doc ,
632
619
'Exactly one of `doc` or `docs` needs to be set'
633
620
) ;
634
- let count = 0 ;
635
621
return sequence ( watchEntity . docs , ( specDocument : SpecDocument ) => {
636
- count ++ ;
637
- const isLast = count === watchEntity . docs ! . length ;
638
- return this . doWatchEntity (
639
- {
640
- doc : specDocument ,
641
- targets : watchEntity . targets ,
642
- removedTargets : watchEntity . removedTargets
643
- } ,
644
- isLast ? watchSnapshot : undefined
645
- ) ;
622
+ return this . doWatchEntity ( {
623
+ doc : specDocument ,
624
+ targets : watchEntity . targets ,
625
+ removedTargets : watchEntity . removedTargets
626
+ } ) ;
646
627
} ) ;
647
628
} else if ( watchEntity . doc ) {
648
629
const [ key , version , data ] = watchEntity . doc ;
@@ -655,7 +636,7 @@ abstract class TestRunner {
655
636
document . key ,
656
637
document
657
638
) ;
658
- return this . doWatchEvent ( change , watchSnapshot ) ;
639
+ return this . doWatchEvent ( change ) ;
659
640
} else if ( watchEntity . key ) {
660
641
const documentKey = key ( watchEntity . key ) ;
661
642
const change = new DocumentWatchChange (
@@ -664,16 +645,13 @@ abstract class TestRunner {
664
645
documentKey ,
665
646
null
666
647
) ;
667
- return this . doWatchEvent ( change , watchSnapshot ) ;
648
+ return this . doWatchEvent ( change ) ;
668
649
} else {
669
650
return fail ( 'Either doc or docs must be set' ) ;
670
651
}
671
652
}
672
653
673
- private doWatchFilter (
674
- watchFilter : SpecWatchFilter ,
675
- watchSnapshot ?: SpecSnapshotVersion
676
- ) : Promise < void > {
654
+ private doWatchFilter ( watchFilter : SpecWatchFilter ) : Promise < void > {
677
655
const targetIds : TargetId [ ] = watchFilter [ 0 ] ;
678
656
assert (
679
657
targetIds . length === 1 ,
@@ -682,31 +660,31 @@ abstract class TestRunner {
682
660
const keys = watchFilter . slice ( 1 ) ;
683
661
const filter = new ExistenceFilter ( keys . length ) ;
684
662
const change = new ExistenceFilterChange ( targetIds [ 0 ] , filter ) ;
685
- return this . doWatchEvent ( change , watchSnapshot ) ;
663
+ return this . doWatchEvent ( change ) ;
686
664
}
687
665
688
- private doWatchEvent (
689
- watchChange : WatchChange ,
690
- watchSnapshot ?: SpecSnapshotVersion
691
- ) : Promise < void > {
692
- let protoJSON = this . serializer . toTestWatchChange ( watchChange ) ;
693
- this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
694
-
666
+ private doWatchSnapshot ( watchSnapshot : SpecWatchSnapshot ) : Promise < void > {
695
667
// The client will only respond to watchSnapshots if they are on a target
696
668
// change with an empty set of target IDs. So we should be sure to send a
697
- // separate event. TODO(klimt): We should make the spec tests behave more
698
- // like the backend. Alternatively, we could hook in to the system at a
699
- // level higher than the stream.
700
- const snapshot =
701
- watchSnapshot !== undefined ? version ( watchSnapshot ) : undefined ;
702
- if ( snapshot ) {
703
- protoJSON = {
704
- targetChange : {
705
- readTime : this . serializer . toVersion ( snapshot )
706
- }
707
- } ;
708
- this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
709
- }
669
+ // separate event.
670
+ const protoJSON : api . ListenResponse = {
671
+ targetChange : {
672
+ readTime : this . serializer . toVersion ( version ( watchSnapshot . version ) ) ,
673
+ resumeToken : watchSnapshot . resumeToken ,
674
+ targetIds : watchSnapshot . targetIds
675
+ }
676
+ } ;
677
+ this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
678
+
679
+ // Put a no-op in the queue so that we know when any outstanding RemoteStore
680
+ // writes on the network are complete.
681
+ return this . queue . enqueue ( async ( ) => { } ) ;
682
+ }
683
+
684
+ private async doWatchEvent ( watchChange : WatchChange ) : Promise < void > {
685
+ const protoJSON = this . serializer . toTestWatchChange ( watchChange ) ;
686
+ this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
687
+
710
688
// Put a no-op in the queue so that we know when any outstanding RemoteStore
711
689
// writes on the network are complete.
712
690
return this . queue . enqueue ( async ( ) => { } ) ;
@@ -1078,7 +1056,7 @@ export interface SpecConfig {
1078
1056
}
1079
1057
1080
1058
/**
1081
- * Union type for each step. The step consists of (mostly) exactly one `field`
1059
+ * Union type for each step. The step consists of exactly one `field`
1082
1060
* set and optionally expected events in the `expect` field.
1083
1061
*/
1084
1062
export interface SpecStep {
@@ -1105,11 +1083,8 @@ export interface SpecStep {
1105
1083
watchEntity ?: SpecWatchEntity ;
1106
1084
/** Existence filter in the watch stream */
1107
1085
watchFilter ?: SpecWatchFilter ;
1108
- /**
1109
- * Optional snapshot version that can be additionally specified on any other
1110
- * watch event
1111
- */
1112
- watchSnapshot ?: SpecSnapshotVersion ;
1086
+ /** Snapshot ("NO_CHANGE") event in the watch stream. */
1087
+ watchSnapshot ?: SpecWatchSnapshot ;
1113
1088
/** A step that the watch stream restarts. */
1114
1089
watchStreamClose ?: SpecWatchStreamClose ;
1115
1090
@@ -1183,7 +1158,11 @@ export type SpecWatchRemove = {
1183
1158
cause ?: SpecError ;
1184
1159
} ;
1185
1160
1186
- export type SpecSnapshotVersion = TestSnapshotVersion ;
1161
+ export type SpecWatchSnapshot = {
1162
+ version : TestSnapshotVersion ;
1163
+ targetIds : TargetId [ ] ;
1164
+ resumeToken ?: string ;
1165
+ } ;
1187
1166
1188
1167
export type SpecWatchStreamClose = {
1189
1168
error : SpecError ;
@@ -1192,7 +1171,7 @@ export type SpecWatchStreamClose = {
1192
1171
1193
1172
export type SpecWriteAck = {
1194
1173
/** The version the backend uses to ack the write. */
1195
- version : SpecSnapshotVersion ;
1174
+ version : TestSnapshotVersion ;
1196
1175
/** Whether the ack is expected to generate a user callback. */
1197
1176
expectUserCallback : boolean ;
1198
1177
} ;
@@ -1257,7 +1236,7 @@ export interface SpecQuery {
1257
1236
*/
1258
1237
export type SpecDocument = [
1259
1238
string ,
1260
- SpecSnapshotVersion ,
1239
+ TestSnapshotVersion ,
1261
1240
JsonObject < AnyJs > | null
1262
1241
] ;
1263
1242
0 commit comments