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

Add test for shared history visibility over federation #716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
48 changes: 48 additions & 0 deletions tests/federation_room_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,51 @@ func TestNetworkPartitionOrdering(t *testing.T) {
},
})
}

// Tests that /sync v2 returns the correct timeline for the following situation _over federation_:
// - Alice and Bob in a room.
// - Bob leaves the room.
// - Alice sends a message.
// - Bob joins the room.
// - The next sync response should include a timeline which ends with [BOB_LEAVE, ALICE_MSG, BOB_JOIN].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be perfectly valid to return just BOB_JOIN here, which I thought we did

//
// In practice, it seems Synapse can respond with [BOB_LEAVE, BOB_JOIN], despite the room being shared history visibility.
func TestSyncDeliversAllTimelineEventsInSharedHistoryRooms(t *testing.T) {
deployment := complement.Deploy(t, 2)
defer deployment.Destroy(t)

// alice and bob in a room
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{})
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "public_chat",
})
bob.MustJoinRoom(t, roomID, []string{"hs1"})
_, nextBatch := bob.MustSync(t, client.SyncReq{})

// bob leaves and alice sends a message
bob.MustLeaveRoom(t, roomID)
eventID := alice.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Sent when Bob has left",
},
})
_, nextBatch = bob.MustSync(t, client.SyncReq{Since: nextBatch})

// bob rejoins and syncs, he should see this message
bob.MustJoinRoom(t, roomID, []string{"hs1"})
syncResponse, _ := bob.MustSync(t, client.SyncReq{Since: nextBatch})
timeline := syncResponse.Get(fmt.Sprintf("rooms.join.%s.timeline.events", client.GjsonEscape(roomID)))
t.Logf("timeline => %v", timeline.Raw)
timelineArray := timeline.Array()
must.NotEqual(t, len(timelineArray), 0, "no timeline for room "+roomID)
must.Equal(t, len(timelineArray) >= 3, true, "need at least 3 timeline events for the room")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't print the number of events there are, which makes seeing how Synapse is failing hard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raw timeline is logged on :289 which seems to be nothing:

2024-03-05T17:36:31.3391923Z     client.go:631: [CSAPI] GET hs2/_matrix/client/v3/sync => 200 OK (21.832274ms)
2024-03-05T17:36:31.3392485Z     federation_room_send_test.go:289: timeline => 
2024-03-05T17:36:31.3393366Z     federation_room_send_test.go:291: �[31mNotEqual no timeline for room !mmzAHLfjZSvFNZKCgv:hs1: got '0', want '0'�[39m
2024-03-05T17:36:31.3394808Z     federation_room_send_test.go:292: �[31mEqual need at least 3 timeline events for the room: got 'false' want 'true'�[39m

// last event is the join
must.MatchGJSON(t, timelineArray[len(timelineArray)-1], match.JSONKeyEqual("content.membership", "join"))
// 2nd to last is the message
must.MatchGJSON(t, timelineArray[len(timelineArray)-2], match.JSONKeyEqual("event_id", eventID))
// 3rd to last is the leave
must.MatchGJSON(t, timelineArray[len(timelineArray)-3], match.JSONKeyEqual("content.membership", "leave"))
}
Loading