@@ -220,7 +220,7 @@ func TestImportHistoricalMessages(t *testing.T) {
220220 validateBatchSendRes (t , as , roomID , batchSendRes , false )
221221 })
222222
223- t .Run ("Historical events from / batch_send do not come down in an incremental sync" , func (t * testing.T ) {
223+ t .Run ("Historical events from batch_send do not come down in an incremental sync" , func (t * testing.T ) {
224224 t .Parallel ()
225225
226226 roomID := as .CreateRoom (t , createPublicRoomOpts )
@@ -234,6 +234,10 @@ func TestImportHistoricalMessages(t *testing.T) {
234234 // Create some "live" events to saturate and fill up the /sync response
235235 createMessagesInRoom (t , alice , roomID , 5 )
236236
237+ // Get a /sync `since` pagination token we can try paginating from later
238+ // on
239+ since := doInitialSync (t , alice )
240+
237241 // Import a historical event
238242 batchSendRes := batchSendHistoricalMessages (
239243 t ,
@@ -248,19 +252,20 @@ func TestImportHistoricalMessages(t *testing.T) {
248252 )
249253 batchSendResBody := client .ParseJSON (t , batchSendRes )
250254 historicalEventIDs := client .GetJSONFieldStringArray (t , batchSendResBody , "event_ids" )
251- historicalEventId := historicalEventIDs [ 0 ]
255+ historicalStateEventIDs := client . GetJSONFieldStringArray ( t , batchSendResBody , "state_event_ids" )
252256
253- // This is just a dummy event we search for after the historicalEventId
257+ // This is just a dummy event we search for after the historicalEventIDs/historicalStateEventIDs
254258 eventIDsAfterHistoricalImport := createMessagesInRoom (t , alice , roomID , 1 )
255259 eventIDAfterHistoricalImport := eventIDsAfterHistoricalImport [0 ]
256260
257- // Sync until we find the eventIDAfterHistoricalImport.
258- // If we're able to see the eventIDAfterHistoricalImport that occurs after
259- // the historicalEventId without seeing eventIDAfterHistoricalImport in
260- // between, we're probably safe to assume it won't sync
261- alice .SyncUntil (t , "" , `{ "room": { "timeline": { "limit": 3 } } }` , "rooms.join." + client .GjsonEscape (roomID )+ ".timeline.events" , func (r gjson.Result ) bool {
262- if r .Get ("event_id" ).Str == historicalEventId {
263- t .Fatalf ("We should not see the %s historical event in /sync response but it was present" , historicalEventId )
261+ // Sync from before we did any batch sending until we find the
262+ // eventIDAfterHistoricalImport. If we're able to see
263+ // eventIDAfterHistoricalImport without any the
264+ // historicalEventIDs/historicalStateEventIDs in between, we're probably
265+ // safe to assume it won't sync.
266+ alice .SyncUntil (t , since , "" , "rooms.join." + client .GjsonEscape (roomID )+ ".timeline.events" , func (r gjson.Result ) bool {
267+ if includes (r .Get ("event_id" ).Str , historicalEventIDs ) || includes (r .Get ("event_id" ).Str , historicalStateEventIDs ) {
268+ t .Fatalf ("We should not see the %s historical event in /sync response but it was present" , r .Get ("event_id" ).Str )
264269 }
265270
266271 return r .Get ("event_id" ).Str == eventIDAfterHistoricalImport
@@ -992,6 +997,17 @@ func reversed(in []string) []string {
992997 return out
993998}
994999
1000+ // Find a given "needle" string in a list of strings, the haystack
1001+ func includes (needle string , haystack []string ) bool {
1002+ for _ , item := range haystack {
1003+ if needle == item {
1004+ return true
1005+ }
1006+ }
1007+
1008+ return false
1009+ }
1010+
9951011func fetchUntilMessagesResponseHas (t * testing.T , c * client.CSAPI , roomID string , check func (gjson.Result ) bool ) {
9961012 t .Helper ()
9971013 start := time .Now ()
0 commit comments