@@ -3,6 +3,7 @@ package csapi_tests
33import (
44 "net/http"
55 "testing"
6+ "time"
67
78 "github.com/matrix-org/complement/internal/b"
89 "github.com/matrix-org/complement/internal/client"
@@ -82,13 +83,36 @@ func TestRoomAlias(t *testing.T) {
8283
8384 setRoomAliasResp (t , alice , roomID , roomAlias )
8485
85- res = listRoomAliasesResp (t , alice , roomID )
86-
87- must .MatchResponse (t , res , match.HTTPResponse {
88- JSON : []match.JSON {
89- match .JSONKeyEqual ("aliases" , []interface {}{roomAlias }),
90- },
91- })
86+ // Synapse doesn't read-after-write consistency here; it can race:
87+ //
88+ // 1. Request to set the alias arrives on a writer worker.
89+ // 2. Writer tells the reader worker to invalidate its caches.
90+ // 3. Response received by the client.
91+ // 4. A new query arrives at the reader.
92+ //
93+ // If (4) arrives at the reader before (2), the reader responds with
94+ // old data. Bodge around this by retrying for up to a second.
95+ res = alice .DoFunc (
96+ t ,
97+ "GET" ,
98+ []string {"_matrix" , "client" , "v3" , "rooms" , roomID , "aliases" },
99+ client .WithRetryUntil (
100+ 1 * time .Second ,
101+ func (res * http.Response ) bool {
102+ if res .StatusCode != 200 {
103+ return false
104+ }
105+ eventResBody := client .ParseJSON (t , res )
106+ matcher := match .JSONKeyEqual ("aliases" , []interface {}{roomAlias })
107+ err := matcher (eventResBody )
108+ if err != nil {
109+ t .Log (err )
110+ return false
111+ }
112+ return true
113+ },
114+ ),
115+ )
92116 })
93117
94118 // sytest: Only room members can list aliases of a room
0 commit comments