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

Deflake GET /rooms/:room_id/aliases lists aliases #521

Merged
merged 1 commit into from
Oct 18, 2022
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
38 changes: 31 additions & 7 deletions tests/csapi/apidoc_room_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package csapi_tests
import (
"net/http"
"testing"
"time"

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/client"
Expand Down Expand Up @@ -82,13 +83,36 @@ func TestRoomAlias(t *testing.T) {

setRoomAliasResp(t, alice, roomID, roomAlias)

res = listRoomAliasesResp(t, alice, roomID)

must.MatchResponse(t, res, match.HTTPResponse{
JSON: []match.JSON{
match.JSONKeyEqual("aliases", []interface{}{roomAlias}),
},
})
// Synapse doesn't read-after-write consistency here; it can race:
//
// 1. Request to set the alias arrives on a writer worker.
// 2. Writer tells the reader worker to invalidate its caches.
// 3. Response received by the client.
// 4. A new query arrives at the reader.
//
// If (4) arrives at the reader before (2), the reader responds with
// old data. Bodge around this by retrying for up to a second.
res = alice.DoFunc(
t,
"GET",
[]string{"_matrix", "client", "v3", "rooms", roomID, "aliases"},
client.WithRetryUntil(
1*time.Second,
func(res *http.Response) bool {
if res.StatusCode != 200 {
return false
}
eventResBody := client.ParseJSON(t, res)
matcher := match.JSONKeyEqual("aliases", []interface{}{roomAlias})
err := matcher(eventResBody)
if err != nil {
t.Log(err)
return false
}
Comment on lines +105 to +111
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This didn't feel very idiomatic. I looked at using must.MatchResponse instead, but that seems to t.Fatalf() on failure to match---which presumably would interrupt the retry mechanism?

return true
},
),
)
})

// sytest: Only room members can list aliases of a room
Expand Down