Skip to content

Commit ab6cf55

Browse files
authored
Fix setup for TestMembersLocal tests and split into sync types (#563)
Depending on timings, the "Existing members see new members' presence" test in `TestMembersLocal` may see the expected join and presence in an initial or incremental sync. Both types of sync elicit different behaviour in homeserver implementations, such as Synapse. Split the test into initial and incremental sync variants to eliminate the race condition. In addition, fix the initial sync case by explicitly setting Bob's presence to online. The spec does not guarantee that Bob will have a non-offline presence after merely joining a room, nor does the spec guarantee that offline presences will show up in initial syncs. Fixes matrix-org/synapse#13199.
1 parent 3d64201 commit ab6cf55

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/csapi/rooms_members_local_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ func TestMembersLocal(t *testing.T) {
1616
bob := deployment.Client(t, "hs1", "@bob:hs1")
1717
roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
1818

19+
bob.MustDoFunc(
20+
t, "PUT", []string{"_matrix", "client", "v3", "presence", bob.UserID, "status"},
21+
client.WithJSONBody(t, map[string]interface{}{
22+
"presence": "online",
23+
}),
24+
)
25+
26+
_, incrementalSyncToken := alice.MustSync(t, client.SyncReq{})
27+
bob.JoinRoom(t, roomID, []string{})
28+
1929
t.Run("Parallel", func(t *testing.T) {
2030
// sytest: New room members see their own join event
2131
t.Run("New room members see their own join event", func(t *testing.T) {
@@ -27,20 +37,32 @@ func TestMembersLocal(t *testing.T) {
2737
// sytest: Existing members see new members' join events
2838
t.Run("Existing members see new members' join events", func(t *testing.T) {
2939
t.Parallel()
30-
bob.JoinRoom(t, roomID, []string{})
3140
// SyncJoinedTo already checks everything we need to know
3241
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
3342
})
3443

3544
// sytest: Existing members see new members' presence
36-
t.Run("Existing members see new members' presence", func(t *testing.T) {
45+
// Split into initial and incremental sync cases in Complement.
46+
t.Run("Existing members see new members' presence in initial sync", func(t *testing.T) {
3747
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/2803
3848
t.Parallel()
49+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
3950
alice.MustSyncUntil(t, client.SyncReq{},
4051
client.SyncJoinedTo(bob.UserID, roomID),
4152
client.SyncPresenceHas(bob.UserID, nil),
4253
)
4354
})
55+
56+
// sytest: Existing members see new members' presence
57+
// Split into initial and incremental sync cases in Complement.
58+
t.Run("Existing members see new members' presence in incremental sync", func(t *testing.T) {
59+
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/2803
60+
t.Parallel()
61+
alice.MustSyncUntil(t, client.SyncReq{Since: incrementalSyncToken},
62+
client.SyncJoinedTo(bob.UserID, roomID),
63+
client.SyncPresenceHas(bob.UserID, nil),
64+
)
65+
})
4466
})
4567

4668
}

0 commit comments

Comments
 (0)