Make checkRequest private

to encourage you to use the setter, which grabs the mutex
This commit is contained in:
David Robertson 2023-09-05 18:08:27 +01:00
parent 02a3b7d364
commit 8e9bb4f842
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
2 changed files with 6 additions and 6 deletions

View File

@ -44,7 +44,7 @@ func TestSecondPollerFiltersToDevice(t *testing.T) {
deviceBToken := "DEVICE_B_TOKEN"
v2.addAccountWithDeviceID(alice, "B", deviceBToken)
seenInitialRequest := false
v2.CheckRequest = func(userID, token string, req *http.Request) {
v2.SetCheckRequest(func(userID, token string, req *http.Request) {
if userID != alice || token != deviceBToken {
return
}
@ -88,7 +88,7 @@ func TestSecondPollerFiltersToDevice(t *testing.T) {
}
seenInitialRequest = true
}
})
wantMsg := json.RawMessage(`{"type":"f","content":{"f":"b"}}`)
v2.queueResponse(deviceBToken, sync2.SyncResponse{

View File

@ -50,11 +50,11 @@ var (
// testV2Server is a fake stand-in for the v2 sync API provided by a homeserver.
type testV2Server struct {
// CheckRequest is an arbitrary function which runs after a request has been
// checkRequest is an arbitrary function which runs after a request has been
// received from pollers, but before the response is generated. This allows us to
// confirm that the proxy is polling the homeserver's v2 sync endpoint in the
// manner that we expect.
CheckRequest func(userID, token string, req *http.Request)
checkRequest func(userID, token string, req *http.Request)
mu *sync.Mutex
tokenToUser map[string]string
tokenToDevice map[string]string
@ -68,7 +68,7 @@ type testV2Server struct {
func (s *testV2Server) SetCheckRequest(fn func(userID, token string, req *http.Request)) {
s.mu.Lock()
defer s.mu.Unlock()
s.CheckRequest = fn
s.checkRequest = fn
}
// Most tests only use a single device per user. Give them this helper so they don't
@ -265,7 +265,7 @@ func runTestV2Server(t testutils.TestBenchInterface) *testV2Server {
return
}
server.mu.Lock()
check := server.CheckRequest
check := server.checkRequest
server.mu.Unlock()
if check != nil {
check(userID, token, req)