Skip to content

Commit

Permalink
Fix an out of bounds error in TestSync 'sync should succeed even if t…
Browse files Browse the repository at this point in the history
…he sync token points to a redaction of an unknown event' (#427)
  • Loading branch information
reivilibre authored Jul 27, 2022
1 parent 9260467 commit d041f19
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/csapi/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func TestSync(t *testing.T) {
Content: map[string]interface{}{"body": "1234"},
})
sentinelRoom.AddEvent(sentinelEvent)
t.Logf("Created sentinel event %s", sentinelEvent.EventID())
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{redactionEvent.JSON(), sentinelEvent.JSON()}, nil)

// wait for the sentinel to arrive
Expand Down Expand Up @@ -343,6 +344,7 @@ func TestSync(t *testing.T) {
// keep the same ?since each time, instead of incrementally syncing on each pass.
numResponsesReturned := 0
start := time.Now()
t.Logf("Will sync with since=%s", nextBatch)
for {
if time.Since(start) > alice.SyncUntilTimeout {
t.Fatalf("%s: timed out after %v. Seen %d /sync responses", alice.UserID, time.Since(start), numResponsesReturned)
Expand All @@ -352,16 +354,22 @@ func TestSync(t *testing.T) {
numResponsesReturned += 1
timeline := syncResponse.Get("rooms.join." + client.GjsonEscape(redactionRoomID) + ".timeline")
timelineEvents := timeline.Get("events").Array()
lastEventIdInSync := timelineEvents[len(timelineEvents)-1].Get("event_id").String()

t.Logf("Iteration %d: /sync returned %d events, with final event %s", numResponsesReturned, len(timelineEvents), lastEventIdInSync)
if lastEventIdInSync == lastSentEventId {
// check we actually got a gappy sync - else this test isn't testing the right thing
if !timeline.Get("limited").Bool() {
t.Fatalf("Not a gappy sync after redaction")
if len(timelineEvents) > 0 {
lastEventIdInSync := timelineEvents[len(timelineEvents)-1].Get("event_id").String()
t.Logf("Iteration %d: /sync returned %d events, with final event %s", numResponsesReturned, len(timelineEvents), lastEventIdInSync)

if lastEventIdInSync == lastSentEventId {
// check we actually got a gappy sync - else this test isn't testing the right thing
if !timeline.Get("limited").Bool() {
t.Fatalf("Not a gappy sync after redaction")
}
break
}
break
} else {
t.Logf("Iteration %d: /sync returned %d events", numResponsesReturned, len(timelineEvents))
}

}

// that's it - we successfully did a gappy sync.
Expand Down

0 comments on commit d041f19

Please sign in to comment.