@@ -482,6 +482,9 @@ abstract class TestRunner {
482
482
return this . doRestart ( ) ;
483
483
} else if ( 'changeUser' in step ) {
484
484
return this . doChangeUser ( step . changeUser ! ) ;
485
+ } else if ( 'watchSnapshot' in step ) {
486
+ // Handle a single `watchSnapshot` event without any other watch change
487
+ return this . doWatchSnapshot ( step . watchSnapshot ! ) ;
485
488
} else {
486
489
return fail ( 'Unknown step: ' + JSON . stringify ( step ) ) ;
487
490
}
@@ -556,7 +559,7 @@ abstract class TestRunner {
556
559
557
560
private doWatchAck (
558
561
ackedTargets : SpecWatchAck ,
559
- watchSnapshot ?: SpecSnapshotVersion
562
+ watchSnapshot ?: SpecWatchSnapshot
560
563
) : Promise < void > {
561
564
const change = new WatchTargetChange (
562
565
WatchTargetChangeState . Added ,
@@ -567,7 +570,7 @@ abstract class TestRunner {
567
570
568
571
private doWatchCurrent (
569
572
currentTargets : SpecWatchCurrent ,
570
- watchSnapshot ?: SpecSnapshotVersion
573
+ watchSnapshot ?: SpecWatchSnapshot
571
574
) : Promise < void > {
572
575
const targets = currentTargets [ 0 ] ;
573
576
const resumeToken = currentTargets [ 1 ] as ProtoByteString ;
@@ -581,7 +584,7 @@ abstract class TestRunner {
581
584
582
585
private doWatchReset (
583
586
targetIds : SpecWatchReset ,
584
- watchSnapshot ?: SpecSnapshotVersion
587
+ watchSnapshot ?: SpecWatchSnapshot
585
588
) : Promise < void > {
586
589
const change = new WatchTargetChange (
587
590
WatchTargetChangeState . Reset ,
@@ -592,7 +595,7 @@ abstract class TestRunner {
592
595
593
596
private doWatchRemove (
594
597
removed : SpecWatchRemove ,
595
- watchSnapshot ?: SpecSnapshotVersion
598
+ watchSnapshot ?: SpecWatchSnapshot
596
599
) : Promise < void > {
597
600
const cause =
598
601
removed . cause &&
@@ -624,7 +627,7 @@ abstract class TestRunner {
624
627
625
628
private doWatchEntity (
626
629
watchEntity : SpecWatchEntity ,
627
- watchSnapshot ?: SpecSnapshotVersion
630
+ watchSnapshot ?: SpecWatchSnapshot
628
631
) : Promise < void > {
629
632
if ( watchEntity . docs ) {
630
633
assert (
@@ -672,7 +675,7 @@ abstract class TestRunner {
672
675
673
676
private doWatchFilter (
674
677
watchFilter : SpecWatchFilter ,
675
- watchSnapshot ?: SpecSnapshotVersion
678
+ watchSnapshot ?: SpecWatchSnapshot
676
679
) : Promise < void > {
677
680
const targetIds : TargetId [ ] = watchFilter [ 0 ] ;
678
681
assert (
@@ -685,27 +688,39 @@ abstract class TestRunner {
685
688
return this . doWatchEvent ( change , watchSnapshot ) ;
686
689
}
687
690
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
-
691
+ private doWatchSnapshot ( watchSnapshot : SpecWatchSnapshot ) : Promise < void > {
695
692
// The client will only respond to watchSnapshots if they are on a target
696
693
// change with an empty set of target IDs. So we should be sure to send a
697
694
// separate event. TODO(klimt): We should make the spec tests behave more
698
695
// like the backend. Alternatively, we could hook in to the system at a
699
696
// 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 ) ;
697
+ const protoJSON : api . ListenResponse = {
698
+ targetChange : {
699
+ readTime : this . serializer . toVersion ( version ( watchSnapshot . version ) )
700
+ }
701
+ } ;
702
+ if ( watchSnapshot . resumeToken ) {
703
+ protoJSON . targetChange . resumeToken = watchSnapshot . resumeToken ;
704
+ }
705
+ if ( watchSnapshot . targetIds ) {
706
+ protoJSON . targetChange . targetIds = watchSnapshot . targetIds ;
707
+ }
708
+ this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
709
+
710
+ // Put a no-op in the queue so that we know when any outstanding RemoteStore
711
+ // writes on the network are complete.
712
+ return this . queue . enqueue ( async ( ) => { } ) ;
713
+ }
714
+
715
+ private async doWatchEvent (
716
+ watchChange : WatchChange ,
717
+ watchSnapshot ?: SpecWatchSnapshot
718
+ ) : Promise < void > {
719
+ const protoJSON = this . serializer . toTestWatchChange ( watchChange ) ;
720
+ this . connection . watchStream ! . callOnMessage ( protoJSON ) ;
721
+
722
+ if ( watchSnapshot ) {
723
+ await this . doWatchSnapshot ( watchSnapshot ) ;
709
724
}
710
725
// Put a no-op in the queue so that we know when any outstanding RemoteStore
711
726
// writes on the network are complete.
@@ -1109,7 +1124,7 @@ export interface SpecStep {
1109
1124
* Optional snapshot version that can be additionally specified on any other
1110
1125
* watch event
1111
1126
*/
1112
- watchSnapshot ?: SpecSnapshotVersion ;
1127
+ watchSnapshot ?: SpecWatchSnapshot ;
1113
1128
/** A step that the watch stream restarts. */
1114
1129
watchStreamClose ?: SpecWatchStreamClose ;
1115
1130
@@ -1183,7 +1198,11 @@ export type SpecWatchRemove = {
1183
1198
cause ?: SpecError ;
1184
1199
} ;
1185
1200
1186
- export type SpecSnapshotVersion = TestSnapshotVersion ;
1201
+ export type SpecWatchSnapshot = {
1202
+ version : TestSnapshotVersion ;
1203
+ targetIds : TargetId [ ] ;
1204
+ resumeToken ?: string ;
1205
+ } ;
1187
1206
1188
1207
export type SpecWatchStreamClose = {
1189
1208
error : SpecError ;
@@ -1192,7 +1211,7 @@ export type SpecWatchStreamClose = {
1192
1211
1193
1212
export type SpecWriteAck = {
1194
1213
/** The version the backend uses to ack the write. */
1195
- version : SpecSnapshotVersion ;
1214
+ version : TestSnapshotVersion ;
1196
1215
/** Whether the ack is expected to generate a user callback. */
1197
1216
expectUserCallback : boolean ;
1198
1217
} ;
@@ -1257,7 +1276,7 @@ export interface SpecQuery {
1257
1276
*/
1258
1277
export type SpecDocument = [
1259
1278
string ,
1260
- SpecSnapshotVersion ,
1279
+ TestSnapshotVersion ,
1261
1280
JsonObject < AnyJs > | null
1262
1281
] ;
1263
1282
0 commit comments