Skip to content

Commit

Permalink
Use WithRetryUntil in publishAndCheckRoomJoinRule
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Jul 22, 2022
1 parent 9db518e commit 5eb18d2
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions tests/knocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"testing"
"time"

"net/http"

"github.com/matrix-org/gomatrixserverlib"
"github.com/tidwall/gjson"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5eb18d2

Please sign in to comment.