Skip to content

Commit 73de567

Browse files
authored
Retry /publicRooms a few times to allow for propagation delay before a new room appears in the room directory (#415)
1 parent 14c156d commit 73de567

File tree

2 files changed

+60
-52
lines changed

2 files changed

+60
-52
lines changed

tests/csapi/apidoc_room_state_test.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package csapi_tests
33
import (
44
"net/url"
55
"testing"
6+
"time"
67

78
"github.com/tidwall/gjson"
89

910
"github.com/matrix-org/complement/internal/b"
1011
"github.com/matrix-org/complement/internal/client"
1112
"github.com/matrix-org/complement/internal/match"
1213
"github.com/matrix-org/complement/internal/must"
14+
15+
"net/http"
1316
)
1417

1518
func TestRoomState(t *testing.T) {
@@ -104,26 +107,31 @@ func TestRoomState(t *testing.T) {
104107
"preset": "public_chat",
105108
})
106109

107-
res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"})
108-
foundRoom := false
109-
110-
must.MatchResponse(t, res, match.HTTPResponse{
111-
JSON: []match.JSON{
112-
match.JSONKeyPresent("chunk"),
113-
match.JSONArrayEach("chunk", func(val gjson.Result) error {
114-
gotRoomID := val.Get("room_id").Str
115-
if gotRoomID == roomID {
116-
foundRoom = true
117-
return nil
118-
}
119-
return nil
120-
}),
121-
},
122-
})
123-
124-
if !foundRoom {
125-
t.Errorf("failed to find room with id: %s", roomID)
126-
}
110+
authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"},
111+
client.WithRetryUntil(time.Second, func(res *http.Response) bool {
112+
foundRoom := false
113+
114+
must.MatchResponse(t, res, match.HTTPResponse{
115+
JSON: []match.JSON{
116+
match.JSONKeyPresent("chunk"),
117+
match.JSONArrayEach("chunk", func(val gjson.Result) error {
118+
gotRoomID := val.Get("room_id").Str
119+
if gotRoomID == roomID {
120+
foundRoom = true
121+
return nil
122+
}
123+
return nil
124+
}),
125+
},
126+
})
127+
128+
if !foundRoom {
129+
t.Logf("failed to find room with id: %s", roomID)
130+
}
131+
132+
return foundRoom
133+
}),
134+
)
127135
})
128136
// sytest: GET /directory/room/:room_alias yields room ID
129137
t.Run("GET /directory/room/:room_alias yields room ID", func(t *testing.T) {

tests/knocking_test.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"testing"
1515
"time"
1616

17+
"net/http"
18+
1719
"github.com/matrix-org/gomatrixserverlib"
1820
"github.com/tidwall/gjson"
1921

@@ -433,39 +435,37 @@ func publishAndCheckRoomJoinRule(t *testing.T, c *client.CSAPI, roomID, expected
433435
)
434436

435437
// Check that we can see the room in the directory
436-
res := c.MustDo(
437-
t,
438-
"GET",
439-
[]string{"_matrix", "client", "v3", "publicRooms"},
440-
nil,
441-
)
442-
443-
roomFound := false
444-
must.MatchResponse(t, res, match.HTTPResponse{
445-
JSON: []match.JSON{
446-
// For each public room directory chunk (representing a single room entry)
447-
match.JSONArrayEach("chunk", func(r gjson.Result) error {
448-
// If this is our room
449-
if r.Get("room_id").Str == roomID {
450-
roomFound = true
451-
452-
// Check that the join_rule key exists and is as we expect
453-
if roomJoinRule := r.Get("join_rule").Str; roomJoinRule != expectedJoinRule {
454-
return fmt.Errorf(
455-
"'join_rule' key for room in public room chunk is '%s', expected '%s'",
456-
roomJoinRule, expectedJoinRule,
457-
)
458-
}
459-
}
460-
return nil
461-
}),
462-
},
463-
})
438+
c.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"},
439+
client.WithRetryUntil(time.Second, func(res *http.Response) bool {
440+
roomFound := false
441+
must.MatchResponse(t, res, match.HTTPResponse{
442+
JSON: []match.JSON{
443+
// For each public room directory chunk (representing a single room entry)
444+
match.JSONArrayEach("chunk", func(r gjson.Result) error {
445+
// If this is our room
446+
if r.Get("room_id").Str == roomID {
447+
roomFound = true
448+
449+
// Check that the join_rule key exists and is as we expect
450+
if roomJoinRule := r.Get("join_rule").Str; roomJoinRule != expectedJoinRule {
451+
return fmt.Errorf(
452+
"'join_rule' key for room in public room chunk is '%s', expected '%s'",
453+
roomJoinRule, expectedJoinRule,
454+
)
455+
}
456+
}
457+
return nil
458+
}),
459+
},
460+
})
464461

465-
// Check that we did in fact see the room
466-
if !roomFound {
467-
t.Fatalf("Room was not present in public room directory response")
468-
}
462+
// Check that we did in fact see the room
463+
if !roomFound {
464+
t.Logf("Room was not present in public room directory response")
465+
}
466+
return roomFound
467+
}),
468+
)
469469
}
470470

471471
// TestCannotSendNonKnockViaSendKnock checks that we cannot submit anything via /send_knock except a knock

0 commit comments

Comments
 (0)