-
Notifications
You must be signed in to change notification settings - Fork 69
Fix TestDeviceListUpdates flakes
#593
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,13 +98,51 @@ func TestDeviceListUpdates(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // makeBarrier returns a function which tries to act as a barrier for `device_lists.changed` | ||
| // updates. | ||
| // | ||
| // When a remote user has a device list update, an entry is expected to appear in | ||
| // `device_lists.changed` in the `/sync` response. The local homeserver may then query the | ||
| // remote homeserver for the update. Some homeservers (Synapse) may emit extra | ||
| // `device_lists.changed` updates in `/sync` responses after querying keys. | ||
| // | ||
| // The barrier tries to ensure that `device_lists.changed` entries resulting from device list | ||
| // updates and queries before the barrier do not appear in `/sync` responses after the barrier. | ||
| makeBarrier := func( | ||
| t *testing.T, | ||
| deployment *docker.Deployment, | ||
| observingUser *client.CSAPI, | ||
| otherHSName string, | ||
| ) func(t *testing.T, nextBatch string) string { | ||
| t.Helper() | ||
|
|
||
| barry := deployment.RegisterUser(t, otherHSName, generateLocalpart("barry"), "password", false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent choice of username :) |
||
|
|
||
| // The observing user must share a room with the dummy barrier user. | ||
| roomID := barry.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
| observingUser.JoinRoom(t, roomID, []string{otherHSName}) | ||
| observingUser.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(observingUser.UserID, roomID)) | ||
|
|
||
| return func(t *testing.T, nextBatch string) string { | ||
| // Publish a device list update from the barrier user and wait until the observing user | ||
| // sees it. | ||
| uploadNewKeys(t, barry) | ||
| return observingUser.MustSyncUntil( | ||
| t, | ||
| client.SyncReq{Since: nextBatch}, | ||
| syncDeviceListsHas("changed", barry.UserID), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // In all of these test scenarios, there are two users: Alice and Bob. | ||
| // We only care about what Alice sees. | ||
|
|
||
| // testOtherUserJoin tests another user joining a room Alice is already in. | ||
| testOtherUserJoin := func(t *testing.T, deployment *docker.Deployment, hsName string, otherHSName string) { | ||
| alice := deployment.RegisterUser(t, hsName, generateLocalpart("alice"), "password", false) | ||
| bob := deployment.RegisterUser(t, otherHSName, generateLocalpart("bob"), "password", false) | ||
| barrier := makeBarrier(t, deployment, alice, otherHSName) | ||
| checkBobKeys := uploadNewKeys(t, bob) | ||
|
|
||
| roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
|
|
@@ -117,14 +155,14 @@ func TestDeviceListUpdates(t *testing.T) { | |
| bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
|
|
||
| // Check that Alice receives a device list update from Bob | ||
| alice.MustSyncUntil( | ||
| aliceNextBatch = alice.MustSyncUntil( | ||
| t, | ||
| client.SyncReq{Since: aliceNextBatch}, | ||
| syncDeviceListsHas("changed", bob.UserID), | ||
| ) | ||
| mustQueryKeys(t, alice, bob.UserID, checkBobKeys) | ||
| // Some homeservers (Synapse) may emit another `changed` update after querying keys. | ||
| _, aliceNextBatch = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | ||
| aliceNextBatch = barrier(t, aliceNextBatch) | ||
|
|
||
| // Both homeservers think Bob has joined now | ||
| // Bob then updates their device list | ||
|
|
@@ -145,6 +183,7 @@ func TestDeviceListUpdates(t *testing.T) { | |
| ) { | ||
| alice := deployment.RegisterUser(t, hsName, generateLocalpart("alice"), "password", false) | ||
| bob := deployment.RegisterUser(t, otherHSName, generateLocalpart("bob"), "password", false) | ||
| barrier := makeBarrier(t, deployment, alice, otherHSName) | ||
| checkBobKeys := uploadNewKeys(t, bob) | ||
|
|
||
| roomID := bob.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
|
|
@@ -157,14 +196,14 @@ func TestDeviceListUpdates(t *testing.T) { | |
| bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | ||
|
|
||
| // Check that Alice receives a device list update from Bob | ||
| alice.MustSyncUntil( | ||
| aliceNextBatch = alice.MustSyncUntil( | ||
| t, | ||
| client.SyncReq{Since: aliceNextBatch}, | ||
| syncDeviceListsHas("changed", bob.UserID), | ||
| ) | ||
| mustQueryKeys(t, alice, bob.UserID, checkBobKeys) | ||
| // Some homeservers (Synapse) may emit another `changed` update after querying keys. | ||
| _, aliceNextBatch = alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | ||
| aliceNextBatch = barrier(t, aliceNextBatch) | ||
|
|
||
| // Both homeservers think Alice has joined now | ||
| // Bob then updates their device list | ||
|
|
@@ -183,6 +222,7 @@ func TestDeviceListUpdates(t *testing.T) { | |
| testOtherUserLeave := func(t *testing.T, deployment *docker.Deployment, hsName string, otherHSName string) { | ||
| alice := deployment.RegisterUser(t, hsName, generateLocalpart("alice"), "password", false) | ||
| bob := deployment.RegisterUser(t, otherHSName, generateLocalpart("bob"), "password", false) | ||
| barrier := makeBarrier(t, deployment, alice, otherHSName) | ||
| checkBobKeys := uploadNewKeys(t, bob) | ||
|
|
||
| roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
|
|
@@ -192,10 +232,10 @@ func TestDeviceListUpdates(t *testing.T) { | |
| bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
|
|
||
| // Alice performs an initial sync | ||
| alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
| aliceNextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
| mustQueryKeys(t, alice, bob.UserID, checkBobKeys) | ||
| // Some homeservers (Synapse) may emit another `changed` update after querying keys. | ||
| _, aliceNextBatch := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | ||
| aliceNextBatch = barrier(t, aliceNextBatch) | ||
|
|
||
| // Bob leaves the room | ||
| bob.LeaveRoom(t, roomID) | ||
|
|
@@ -226,6 +266,7 @@ func TestDeviceListUpdates(t *testing.T) { | |
| testLeave := func(t *testing.T, deployment *docker.Deployment, hsName string, otherHSName string) { | ||
| alice := deployment.RegisterUser(t, hsName, generateLocalpart("alice"), "password", false) | ||
| bob := deployment.RegisterUser(t, otherHSName, generateLocalpart("bob"), "password", false) | ||
| barrier := makeBarrier(t, deployment, alice, otherHSName) | ||
| checkBobKeys := uploadNewKeys(t, bob) | ||
|
|
||
| roomID := bob.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
|
|
@@ -235,10 +276,10 @@ func TestDeviceListUpdates(t *testing.T) { | |
| bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | ||
|
|
||
| // Alice performs an initial sync | ||
| alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | ||
| aliceNextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | ||
| mustQueryKeys(t, alice, bob.UserID, checkBobKeys) | ||
| // Some homeservers (Synapse) may emit another `changed` update after querying keys. | ||
| _, aliceNextBatch := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | ||
| aliceNextBatch = barrier(t, aliceNextBatch) | ||
|
|
||
| // Alice leaves the room | ||
| alice.LeaveRoom(t, roomID) | ||
|
|
@@ -269,6 +310,7 @@ func TestDeviceListUpdates(t *testing.T) { | |
| testOtherUserRejoin := func(t *testing.T, deployment *docker.Deployment, hsName string, otherHSName string) { | ||
| alice := deployment.RegisterUser(t, hsName, generateLocalpart("alice"), "password", false) | ||
| bob := deployment.RegisterUser(t, otherHSName, generateLocalpart("bob"), "password", false) | ||
| barrier := makeBarrier(t, deployment, alice, otherHSName) | ||
| checkBobKeys := uploadNewKeys(t, bob) | ||
|
|
||
| roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
|
|
@@ -278,10 +320,10 @@ func TestDeviceListUpdates(t *testing.T) { | |
| bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
|
|
||
| // Alice performs an initial sync | ||
| alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
| aliceNextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | ||
| mustQueryKeys(t, alice, bob.UserID, checkBobKeys) | ||
| // Some homeservers (Synapse) may emit another `changed` update after querying keys. | ||
| _, aliceNextBatch := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) | ||
| aliceNextBatch = barrier(t, aliceNextBatch) | ||
|
|
||
| // Both homeservers think Bob has joined now | ||
| // Bob leaves the room | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have I understood this correctly?
We make something new happen in the device lists stream for
barryand wait to see the result happen. Becauseby the time we've seen
device_lists.changedfor barry we will have already seen the "no-op" `device_list.changed" (if it was generated at all).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the idea, yes.