From a2fb32870f3b7adfbc6736358b7a1c14f513a70d Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 4 Apr 2023 12:17:26 +0200 Subject: [PATCH] test/integration/auth: fix data race "username" gets read by one goroutine and written by another. Therefore it must be protected by a mutex to avoid triggering the race detector. --- test/integration/auth/accessreview_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/integration/auth/accessreview_test.go b/test/integration/auth/accessreview_test.go index e621821d630..1272bcedf01 100644 --- a/test/integration/auth/accessreview_test.go +++ b/test/integration/auth/accessreview_test.go @@ -21,6 +21,7 @@ import ( "errors" "net/http" "strings" + "sync" "testing" authorizationapi "k8s.io/api/authorization/v1" @@ -148,8 +149,12 @@ func TestSubjectAccessReview(t *testing.T) { } func TestSelfSubjectAccessReview(t *testing.T) { + var mutex sync.Mutex username := "alice" authenticatorFunc := func(req *http.Request) (*authenticator.Response, bool, error) { + mutex.Lock() + defer mutex.Unlock() + return &authenticator.Response{ User: &user.DefaultInfo{ Name: username, @@ -216,7 +221,9 @@ func TestSelfSubjectAccessReview(t *testing.T) { } for _, test := range tests { + mutex.Lock() username = test.username + mutex.Unlock() response, err := clientset.AuthorizationV1().SelfSubjectAccessReviews().Create(context.TODO(), test.sar, metav1.CreateOptions{}) switch {