@@ -65,6 +65,17 @@ func TestPartialStateJoin(t *testing.T) {
65
65
return serverRoom
66
66
}
67
67
68
+ // getSyncToken gets the latest sync token
69
+ getSyncToken := func (t * testing.T , alice * client.CSAPI ) string {
70
+ _ , syncToken := alice .MustSync (t ,
71
+ client.SyncReq {
72
+ Filter : buildLazyLoadingSyncFilter (nil ),
73
+ TimeoutMillis : "0" ,
74
+ },
75
+ )
76
+ return syncToken
77
+ }
78
+
68
79
// test that a regular /sync request made during a partial-state /send_join
69
80
// request blocks until the state is correctly synced.
70
81
t .Run ("SyncBlocksDuringPartialStateJoin" , func (t * testing.T ) {
@@ -182,6 +193,7 @@ func TestPartialStateJoin(t *testing.T) {
182
193
deployment := Deploy (t , b .BlueprintAlice )
183
194
defer deployment .Destroy (t )
184
195
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
196
+ syncToken := getSyncToken (t , alice )
185
197
186
198
server := createTestServer (t , deployment )
187
199
cancel := server .Listen ()
@@ -197,14 +209,15 @@ func TestPartialStateJoin(t *testing.T) {
197
209
t .Logf ("Derek created event with ID %s" , event .EventID ())
198
210
199
211
// derek sends an event in the room
200
- testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , event )
212
+ testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , event , syncToken )
201
213
})
202
214
203
215
// we should be able to receive events with a missing prev event over federation during the resync
204
216
t .Run ("CanReceiveEventsWithMissingParentsDuringPartialStateJoin" , func (t * testing.T ) {
205
217
deployment := Deploy (t , b .BlueprintAlice )
206
218
defer deployment .Destroy (t )
207
219
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
220
+ syncToken := getSyncToken (t , alice )
208
221
209
222
server := createTestServer (t , deployment )
210
223
cancel := server .Listen ()
@@ -236,14 +249,15 @@ func TestPartialStateJoin(t *testing.T) {
236
249
[]string {eventB .EventID ()}, []* gomatrixserverlib.Event {eventA })
237
250
238
251
// send event B to hs1
239
- testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventB )
252
+ testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventB , syncToken )
240
253
})
241
254
242
255
// we should be able to receive events with partially missing prev events over federation during the resync
243
256
t .Run ("CanReceiveEventsWithHalfMissingParentsDuringPartialStateJoin" , func (t * testing.T ) {
244
257
deployment := Deploy (t , b .BlueprintAlice )
245
258
defer deployment .Destroy (t )
246
259
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
260
+ syncToken := getSyncToken (t , alice )
247
261
248
262
server := createTestServer (t , deployment )
249
263
cancel := server .Listen ()
@@ -277,7 +291,7 @@ func TestPartialStateJoin(t *testing.T) {
277
291
[]string {eventB .EventID ()}, []* gomatrixserverlib.Event {eventA })
278
292
279
293
// send event B to hs1
280
- testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventB )
294
+ testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventB , syncToken )
281
295
})
282
296
283
297
// we should be able to receive events with a missing prev event, with half missing prev events,
@@ -286,6 +300,7 @@ func TestPartialStateJoin(t *testing.T) {
286
300
deployment := Deploy (t , b .BlueprintAlice )
287
301
defer deployment .Destroy (t )
288
302
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
303
+ syncToken := getSyncToken (t , alice )
289
304
290
305
server := createTestServer (t , deployment )
291
306
cancel := server .Listen ()
@@ -323,7 +338,7 @@ func TestPartialStateJoin(t *testing.T) {
323
338
handleStateRequests (t , server , serverRoom , eventA .EventID (), serverRoom .AllCurrentState (), nil , nil )
324
339
325
340
// send event C to hs1
326
- testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventC )
341
+ testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , eventC , syncToken )
327
342
})
328
343
329
344
// a request to (client-side) /members?at= should block until the (federation) /state request completes
@@ -635,6 +650,7 @@ func TestPartialStateJoin(t *testing.T) {
635
650
deployment := Deploy (t , b .BlueprintAlice )
636
651
defer deployment .Destroy (t )
637
652
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
653
+ syncToken := getSyncToken (t , alice )
638
654
639
655
server := createTestServer (t , deployment )
640
656
cancel := server .Listen ()
@@ -692,7 +708,7 @@ func TestPartialStateJoin(t *testing.T) {
692
708
693
709
t .Logf ("Charlie sent timeline event 2" )
694
710
// wait for it to become visible, which implies that all the outliers have been pulled in.
695
- awaitEventArrival (t , time . Second , alice , serverRoom .RoomID , timelineEvent2 .EventID ())
711
+ awaitEventViaSync (t , alice , serverRoom .RoomID , timelineEvent2 .EventID (), syncToken )
696
712
697
713
// now we send over all the other events in the gap.
698
714
server .MustSendTransaction (t , deployment , "hs1" , []json.RawMessage {lateEvent .JSON ()}, nil )
@@ -741,6 +757,7 @@ func TestPartialStateJoin(t *testing.T) {
741
757
deployment := Deploy (t , b .BlueprintAlice )
742
758
defer deployment .Destroy (t )
743
759
alice := deployment .Client (t , "hs1" , "@alice:hs1" )
760
+ syncToken := getSyncToken (t , alice )
744
761
745
762
server := createTestServer (t , deployment )
746
763
cancel := server .Listen ()
@@ -777,7 +794,7 @@ func TestPartialStateJoin(t *testing.T) {
777
794
[]json.RawMessage {badStateEvent .JSON (), sentinelEvent .JSON ()}, nil )
778
795
779
796
// wait for the sentinel event to be visible
780
- awaitEventArrival (t , time . Second , alice , serverRoom .RoomID , sentinelEvent .EventID ())
797
+ syncToken = awaitEventViaSync (t , alice , serverRoom .RoomID , sentinelEvent .EventID (), syncToken )
781
798
782
799
// ... and check that the bad state event is *not* visible
783
800
must .MatchResponse (t ,
@@ -793,7 +810,7 @@ func TestPartialStateJoin(t *testing.T) {
793
810
// one more (non-state) event, for testReceiveEventDuringPartialStateJoin
794
811
event := psjResult .CreateMessageEvent (t , "charlie" , nil )
795
812
t .Logf ("charlie created regular timeline event %s" , event .EventID ())
796
- testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , event )
813
+ testReceiveEventDuringPartialStateJoin (t , deployment , alice , psjResult , event , syncToken )
797
814
798
815
// check that the bad state event is *still* not visible
799
816
must .MatchResponse (t ,
@@ -1214,14 +1231,14 @@ func TestPartialStateJoin(t *testing.T) {
1214
1231
1215
1232
// test reception of an event over federation during a resync
1216
1233
// sends the given event to the homeserver under test, checks that a client can see it and checks
1217
- // the state at the event
1234
+ // the state at the event. returns the new sync token after the event.
1218
1235
func testReceiveEventDuringPartialStateJoin (
1219
- t * testing.T , deployment * docker.Deployment , alice * client.CSAPI , psjResult partialStateJoinResult , event * gomatrixserverlib.Event ,
1220
- ) {
1236
+ t * testing.T , deployment * docker.Deployment , alice * client.CSAPI , psjResult partialStateJoinResult , event * gomatrixserverlib.Event , syncToken string ,
1237
+ ) string {
1221
1238
// send the event to the homeserver
1222
1239
psjResult .Server .MustSendTransaction (t , deployment , "hs1" , []json.RawMessage {event .JSON ()}, nil )
1223
1240
1224
- awaitEventArrival (t , time . Second , alice , psjResult .ServerRoom .RoomID , event .EventID ())
1241
+ syncToken = awaitEventViaSync (t , alice , psjResult .ServerRoom .RoomID , event .EventID (), syncToken )
1225
1242
1226
1243
// fire off a /state_ids request for the last event.
1227
1244
// it must either:
@@ -1274,7 +1291,7 @@ func testReceiveEventDuringPartialStateJoin(
1274
1291
)
1275
1292
if err := psjResult .Server .SendFederationRequest (context .Background (), deployment , stateReq , & respStateIDs ); err != nil {
1276
1293
t .Errorf ("/state_ids request returned non-200: %s" , err )
1277
- return
1294
+ return syncToken
1278
1295
}
1279
1296
var gotState , expectedState []interface {}
1280
1297
for _ , ev := range respStateIDs .StateEventIDs {
@@ -1284,21 +1301,30 @@ func testReceiveEventDuringPartialStateJoin(
1284
1301
expectedState = append (expectedState , ev .EventID ())
1285
1302
}
1286
1303
must .CheckOffAll (t , gotState , expectedState )
1304
+
1305
+ return syncToken
1287
1306
}
1288
1307
1289
- // awaitEventArrival waits for alice to be able to see a given event
1290
- func awaitEventArrival ( t * testing. T , timeout time. Duration , alice * client. CSAPI , roomID string , eventID string ) {
1291
- /* TODO: check that a lazy-loading sync can see the event. Currently this doesn't work, because /sync blocks.
1292
- * https://github.com/matrix-org/synapse/issues/13146
1293
- alice.MustSyncUntil(t,
1308
+ // awaitEventViaSync waits for alice to be able to see a given event via an incremental lazy-loading
1309
+ // /sync and returns the new sync token after
1310
+ func awaitEventViaSync ( t * testing. T , alice * client. CSAPI , roomID string , eventID string , syncToken string ) string {
1311
+ // check that a lazy-loading sync can see the event
1312
+ syncToken = alice .MustSyncUntil (t ,
1294
1313
client.SyncReq {
1314
+ Since : syncToken ,
1295
1315
Filter : buildLazyLoadingSyncFilter (nil ),
1296
1316
},
1297
1317
client .SyncTimelineHasEventID (roomID , eventID ),
1298
1318
)
1299
- */
1300
1319
1301
- // still, Alice should be able to see the event with an /event request. We might have to try it a few times.
1320
+ t .Logf ("Alice successfully received event %s via /sync" , eventID )
1321
+
1322
+ return syncToken
1323
+ }
1324
+
1325
+ // awaitEventArrival waits for alice to be able to see a given event via /event
1326
+ func awaitEventArrival (t * testing.T , timeout time.Duration , alice * client.CSAPI , roomID string , eventID string ) {
1327
+ // Alice should be able to see the event with an /event request. We might have to try it a few times.
1302
1328
alice .DoFunc (t , "GET" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "event" , eventID },
1303
1329
client .WithRetryUntil (timeout , func (res * http.Response ) bool {
1304
1330
if res .StatusCode == 200 {
@@ -1312,7 +1338,7 @@ func awaitEventArrival(t *testing.T, timeout time.Duration, alice *client.CSAPI,
1312
1338
return false
1313
1339
}),
1314
1340
)
1315
- t .Logf ("Alice successfully received event %s" , eventID )
1341
+ t .Logf ("Alice successfully observed event %s via /event " , eventID )
1316
1342
}
1317
1343
1318
1344
// buildLazyLoadingSyncFilter constructs a json-marshalled filter suitable the 'Filter' field of a client.SyncReq
0 commit comments