Deflake gappy state integration test

This commit is contained in:
David Robertson 2023-04-27 15:41:59 +01:00
parent 417a47f4c5
commit 212dc34d78
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
2 changed files with 21 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package syncv3
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"time"
@ -186,7 +187,16 @@ func TestPollerHandlesUnknownStateEventsOnIncrementalSync(t *testing.T) {
res,
m.MatchRoomSubscription(
roomID,
m.MatchRoomTimeline([]json.RawMessage{nameEvent, powerLevelsEvent, messageEvent}),
func(r sync3.Room) error {
// syncv2 doesn't assign any meaning to the order of events in a state
// block, so check for both possibilities
nameFirst := m.MatchRoomTimeline([]json.RawMessage{nameEvent, powerLevelsEvent, messageEvent})
powerLevelsFirst := m.MatchRoomTimeline([]json.RawMessage{powerLevelsEvent, nameEvent, messageEvent})
if nameFirst(r) != nil && powerLevelsFirst(r) != nil {
return fmt.Errorf("did not see state before message")
}
return nil
},
m.MatchRoomName("banana"),
),
)

View File

@ -17,6 +17,16 @@ type ListMatcher func(list sync3.ResponseList) error
type OpMatcher func(op sync3.ResponseOp) error
type RoomMatcher func(r sync3.Room) error
// LogRoom builds a matcher that always succeeds. As a side-effect, it pretty-prints
// the given room to the test log. This is useful when debugging a test.
func LogRoom(t *testing.T) RoomMatcher {
return func(room sync3.Room) error {
dump, _ := json.MarshalIndent(room, "", " ")
t.Logf("Response was: %s", dump)
return nil
}
}
func MatchRoomName(name string) RoomMatcher {
return func(r sync3.Room) error {
if name == "" {