Skip to content

Commit

Permalink
Always ensure integ tests send a timeline event when sending state
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay authored and David Robertson committed Aug 22, 2023
1 parent 4902813 commit d3285a3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
6 changes: 5 additions & 1 deletion tests-integration/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ func TestMaxDBConns(t *testing.T) {
token := fmt.Sprintf("maxconns_%d", n)
roomID := fmt.Sprintf("!maxconns_%d", n)
v2.addAccount(t, userID, token)
state := createRoomState(t, userID, time.Now())
v2.queueResponse(userID, sync2.SyncResponse{
Rooms: sync2.SyncRoomsResponse{
Join: v2JoinTimeline(roomEvents{
roomID: roomID,
state: createRoomState(t, userID, time.Now()),
state: state[:len(state)-1],
events: []json.RawMessage{
state[len(state)-1],
},
}),
},
})
Expand Down
6 changes: 3 additions & 3 deletions tests-integration/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,23 +418,23 @@ func TestExtensionAccountData(t *testing.T) {
Rooms: sync2.SyncRoomsResponse{
Join: map[string]sync2.SyncV2JoinResponse{
roomA: {
State: sync2.EventsResponse{
Timeline: sync2.TimelineResponse{
Events: createRoomState(t, alice, time.Now()),
},
AccountData: sync2.EventsResponse{
Events: roomAAccountData,
},
},
roomB: {
State: sync2.EventsResponse{
Timeline: sync2.TimelineResponse{
Events: createRoomState(t, alice, time.Now().Add(-1*time.Minute)),
},
AccountData: sync2.EventsResponse{
Events: roomBAccountData,
},
},
roomC: {
State: sync2.EventsResponse{
Timeline: sync2.TimelineResponse{
Events: createRoomState(t, alice, time.Now().Add(-2*time.Minute)),
},
AccountData: sync2.EventsResponse{
Expand Down
7 changes: 7 additions & 0 deletions tests-integration/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func TestSecondPollerFiltersToDevice(t *testing.T) {
// to the start of the v2 sync response's timeline, which should then be visible to
// sync v3 clients as ordinary state events in the room timeline.
func TestPollerHandlesUnknownStateEventsOnIncrementalSync(t *testing.T) {
// FIXME: this should resolve once we update downstream caches
t.Skip("We will never see the name/PL event in the timeline with the new code due to those events being part of the state block.")
pqString := testutils.PrepareDBConnectionString()
v2 := runTestV2Server(t)
v3 := runTestServer(t, v2, pqString)
Expand Down Expand Up @@ -209,6 +211,11 @@ func TestPollerHandlesUnknownStateEventsOnIncrementalSync(t *testing.T) {
// that if Alice's poller sees Bob leave in a state block, the events seen in that
// timeline are not visible to Bob.
func TestPollerUpdatesRoomMemberTrackerOnGappySyncStateBlock(t *testing.T) {
// the room state should update to make bob no longer be a member, which should update downstream caches
// DO WE SEND THESE GAPPY STATES TO THE CLIENT? It's NOT part of the timeline, but we need to let the client
// know somehow? I think the best case here would be to invalidate that _room_ (if that were possible in the API)
// to force the client to resync the state.
t.Skip("figure out what the valid thing to do here is")
pqString := testutils.PrepareDBConnectionString()
v2 := runTestV2Server(t)
v3 := runTestServer(t, v2, pqString)
Expand Down
7 changes: 7 additions & 0 deletions tests-integration/rig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func (r *testRig) SetupV2RoomsForUser(t *testing.T, v2UserID string, f FlushEnum
} else {
stateBlock = createRoomState(t, creator, timestamp)
}
// A valid v2 response always has a timeline entry with state.
if len(timeline) == 0 {
timeline = []json.RawMessage{
stateBlock[len(stateBlock)-1],
}
stateBlock = stateBlock[:len(stateBlock)-1]
}
joinRooms[roomID] = sync2.SyncV2JoinResponse{
State: sync2.EventsResponse{
Events: stateBlock,
Expand Down
5 changes: 3 additions & 2 deletions tests-integration/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package syncv3
import (
"encoding/json"
"fmt"
slidingsync "github.com/matrix-org/sliding-sync"
"testing"
"time"

slidingsync "github.com/matrix-org/sliding-sync"

"github.com/matrix-org/sliding-sync/sync2"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/testutils"
Expand Down Expand Up @@ -344,7 +345,7 @@ func TestInitialFlag(t *testing.T) {
Rooms: sync2.SyncRoomsResponse{
Join: v2JoinTimeline(roomEvents{
roomID: roomID,
state: createRoomState(t, alice, time.Now()),
events: createRoomState(t, alice, time.Now()),
}),
},
})
Expand Down
6 changes: 6 additions & 0 deletions tests-integration/v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func (s *testV2Server) deviceID(token string) string {
}

func (s *testV2Server) queueResponse(userIDOrToken string, resp sync2.SyncResponse) {
// ensure we send valid responses
for roomID, room := range resp.Rooms.Join {
if len(room.State.Events) > 0 && len(room.Timeline.Events) == 0 {
panic(fmt.Sprintf("invalid queued v2 response for room %s: no timeline events but %d events in state block", roomID, len(room.State.Events)))
}
}
s.mu.Lock()
ch := s.queues[userIDOrToken]
if ch == nil {
Expand Down

0 comments on commit d3285a3

Please sign in to comment.