Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflake gappy state integration test #88

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests-integration/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package syncv3

import (
"encoding/json"
"fmt"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -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"),
),
)
Expand Down
10 changes: 10 additions & 0 deletions testutils/m/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down