Skip to content

Commit

Permalink
Fix flakey key upload test (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored Sep 5, 2023
1 parent feea136 commit fdb9131
Showing 1 changed file with 17 additions and 3 deletions.
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
}
}
}
return fmt.Errorf("no device_lists found")
})

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

0 comments on commit fdb9131

Please sign in to comment.