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

Initial test for the "device lists" part of the /sync response #714

Merged
merged 2 commits into from
Mar 21, 2024
Merged
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
60 changes: 60 additions & 0 deletions tests/csapi/sync_test.go
Original file line number Diff line number Diff line change
@@ -374,6 +374,66 @@ func TestSync(t *testing.T) {

// that's it - we successfully did a gappy sync.
})

t.Run("Device list tracking", func(t *testing.T) {
// syncDeviceListsHas checks that `device_lists.changed` or `device_lists.left` contains a
// given user ID.
syncDeviceListsHas := func(section string, expectedUserID string) client.SyncCheckOpt {
jsonPath := fmt.Sprintf("device_lists.%s", section)
return func(clientUserID string, topLevelSyncJSON gjson.Result) error {
usersWithChangedDeviceListsArray := topLevelSyncJSON.Get(jsonPath).Array()
for _, userID := range usersWithChangedDeviceListsArray {
if userID.Str == expectedUserID {
return nil
}
}
return fmt.Errorf(
"syncDeviceListsHas: %s not found in %s",
expectedUserID,
jsonPath,
)
}
}

t.Run("User is correctly listed when they leave, even when lazy loading is enabled", func(t *testing.T) {
// Alice creates a room, and starts syncing with lazy-loading enabled.
// Charlie joins, sends an event, and then leaves, the room.
// We check that Charlie appears under the "device_lists" section of the sync.
//
// Regression test for https://github.com/element-hq/synapse/issues/16948

charlie := deployment.Register(t, "hs1", helpers.RegistrationOpts{LocalpartSuffix: "charlie"})
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})

aliceSyncFilter := `{
"room": {
"timeline": { "lazy_load_members": true },
"state": { "lazy_load_members": true }
}
}`
_, initialSyncToken := alice.MustSync(t, client.SyncReq{Filter: aliceSyncFilter})

charlie.MustJoinRoom(t, roomID, nil)
syncToken := alice.MustSyncUntil(t, client.SyncReq{Filter: aliceSyncFilter, Since: initialSyncToken},
syncDeviceListsHas("changed", charlie.UserID),
)

// Charlie sends a message, and leaves
sendMessages(t, charlie, roomID, "test", 1)
charlie.MustLeaveRoom(t, roomID)

// Alice sees charlie in the "left" section
alice.MustSyncUntil(t, client.SyncReq{Filter: aliceSyncFilter, Since: syncToken},
syncDeviceListsHas("left", charlie.UserID),
)

// ... even if she makes the request twice
resp, _ := alice.MustSync(t, client.SyncReq{Filter: aliceSyncFilter, Since: syncToken})
if err := syncDeviceListsHas("left", charlie.UserID)(alice.UserID, resp); err != nil {
t.Error(err)
}
})
})
})
}