diff --git a/tests/csapi/apidoc_room_state_test.go b/tests/csapi/apidoc_room_state_test.go index 83cec69a..b56cb1d9 100644 --- a/tests/csapi/apidoc_room_state_test.go +++ b/tests/csapi/apidoc_room_state_test.go @@ -3,6 +3,7 @@ package csapi_tests import ( "net/url" "testing" + "time" "github.com/tidwall/gjson" @@ -10,6 +11,8 @@ import ( "github.com/matrix-org/complement/internal/client" "github.com/matrix-org/complement/internal/match" "github.com/matrix-org/complement/internal/must" + + "net/http" ) func TestRoomState(t *testing.T) { @@ -104,26 +107,31 @@ func TestRoomState(t *testing.T) { "preset": "public_chat", }) - res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"}) - foundRoom := false - - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - match.JSONKeyPresent("chunk"), - match.JSONArrayEach("chunk", func(val gjson.Result) error { - gotRoomID := val.Get("room_id").Str - if gotRoomID == roomID { - foundRoom = true - return nil - } - return nil - }), - }, - }) - - if !foundRoom { - t.Errorf("failed to find room with id: %s", roomID) - } + authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"}, + client.WithRetryUntil(time.Second, func(res *http.Response) bool { + foundRoom := false + + must.MatchResponse(t, res, match.HTTPResponse{ + JSON: []match.JSON{ + match.JSONKeyPresent("chunk"), + match.JSONArrayEach("chunk", func(val gjson.Result) error { + gotRoomID := val.Get("room_id").Str + if gotRoomID == roomID { + foundRoom = true + return nil + } + return nil + }), + }, + }) + + if !foundRoom { + t.Logf("failed to find room with id: %s", roomID) + } + + return foundRoom + }), + ) }) // sytest: GET /directory/room/:room_alias yields room ID t.Run("GET /directory/room/:room_alias yields room ID", func(t *testing.T) { diff --git a/tests/knocking_test.go b/tests/knocking_test.go index 1a1fd2be..581e958c 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -14,6 +14,8 @@ import ( "testing" "time" + "net/http" + "github.com/matrix-org/gomatrixserverlib" "github.com/tidwall/gjson" @@ -433,39 +435,37 @@ func publishAndCheckRoomJoinRule(t *testing.T, c *client.CSAPI, roomID, expected ) // Check that we can see the room in the directory - res := c.MustDo( - t, - "GET", - []string{"_matrix", "client", "v3", "publicRooms"}, - nil, - ) - - roomFound := false - must.MatchResponse(t, res, match.HTTPResponse{ - JSON: []match.JSON{ - // For each public room directory chunk (representing a single room entry) - match.JSONArrayEach("chunk", func(r gjson.Result) error { - // If this is our room - if r.Get("room_id").Str == roomID { - roomFound = true - - // Check that the join_rule key exists and is as we expect - if roomJoinRule := r.Get("join_rule").Str; roomJoinRule != expectedJoinRule { - return fmt.Errorf( - "'join_rule' key for room in public room chunk is '%s', expected '%s'", - roomJoinRule, expectedJoinRule, - ) - } - } - return nil - }), - }, - }) + c.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"}, + client.WithRetryUntil(time.Second, func(res *http.Response) bool { + roomFound := false + must.MatchResponse(t, res, match.HTTPResponse{ + JSON: []match.JSON{ + // For each public room directory chunk (representing a single room entry) + match.JSONArrayEach("chunk", func(r gjson.Result) error { + // If this is our room + if r.Get("room_id").Str == roomID { + roomFound = true + + // Check that the join_rule key exists and is as we expect + if roomJoinRule := r.Get("join_rule").Str; roomJoinRule != expectedJoinRule { + return fmt.Errorf( + "'join_rule' key for room in public room chunk is '%s', expected '%s'", + roomJoinRule, expectedJoinRule, + ) + } + } + return nil + }), + }, + }) - // Check that we did in fact see the room - if !roomFound { - t.Fatalf("Room was not present in public room directory response") - } + // Check that we did in fact see the room + if !roomFound { + t.Logf("Room was not present in public room directory response") + } + return roomFound + }), + ) } // TestCannotSendNonKnockViaSendKnock checks that we cannot submit anything via /send_knock except a knock