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

Fix flakey key upload test #649

Merged
merged 1 commit into from
Sep 5, 2023
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
20 changes: 17 additions & 3 deletions tests/federation_upload_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func TestFederationKeyUploadQuery(t *testing.T) {
alice := deployment.Client(t, "hs1", "@alice:hs1")
bob := deployment.Client(t, "hs2", "@bob:hs2")

// Do an initial sync so that we can see the changes come down sync.
_, nextBatchBeforeKeyUpload := bob.MustSync(t, client.SyncReq{})

deviceKeys, oneTimeKeys := generateKeys(t, alice, 1)
// Upload keys
reqBody := client.WithJSONBody(t, map[string]interface{}{
Expand Down Expand Up @@ -80,9 +83,20 @@ func TestFederationKeyUploadQuery(t *testing.T) {

// sytest: Can query remote device keys using POST
t.Run("Can query remote device keys using POST", func(t *testing.T) {
// Device list changes only come down incremental syncs, so we do an
// initial sync up front.
_, nextBatch := bob.MustSync(t, client.SyncReq{})
// We expect the key upload to come down /sync. We need to do this so
// that can tell the next device update actually triggers the
// notification to go down /sync.
nextBatch := bob.MustSyncUntil(t, client.SyncReq{Since: nextBatchBeforeKeyUpload}, func(clientUserID string, topLevelSyncJSON gjson.Result) error {
devicesChanged := topLevelSyncJSON.Get("device_lists.changed")
if devicesChanged.Exists() {
for _, userID := range devicesChanged.Array() {
if userID.Str == alice.UserID {
return nil
}
}
}
Comment on lines +90 to +97
Copy link
Contributor

Choose a reason for hiding this comment

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

there might be some clever way to use JSONCheckOffAllowUnwanted here but I usually find that more confusing tbh

return fmt.Errorf("no device_lists found")
})

displayName := "My new displayname"
body := client.WithJSONBody(t, map[string]interface{}{
Expand Down
Loading