From 36f5836cadf8185d671878070654d9101ccf82ed Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Fri, 17 Feb 2023 16:25:29 -0500 Subject: [PATCH 1/2] Fix attempt for test fail panics in xDS --- agent/xds/delta_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/agent/xds/delta_test.go b/agent/xds/delta_test.go index 23d60198bbf8..fcd0d86e4eb3 100644 --- a/agent/xds/delta_test.go +++ b/agent/xds/delta_test.go @@ -4,6 +4,7 @@ import ( "errors" "strconv" "strings" + "sync" "sync/atomic" "testing" "time" @@ -1057,6 +1058,15 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + var stopped bool + var lock sync.RWMutex + + defer func() { + lock.Lock() + stopped = true + lock.Unlock() + }() + aclResolve := func(id string) (acl.Authorizer, error) { if !tt.defaultDeny { // Allow all @@ -1066,6 +1076,14 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { // No token and defaultDeny is denied return acl.RootAuthorizer("deny"), nil } + + lock.RLock() + defer lock.RUnlock() + + if stopped { + return acl.DenyAll().ToAllowAuthorizer(), nil + } + // Ensure the correct token was passed require.Equal(t, tt.token, id) // Parse the ACL and enforce it From f53e0f2cd9b3e6893b9fcc1470a90dabddcd06b8 Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Fri, 17 Feb 2023 16:41:05 -0500 Subject: [PATCH 2/2] switch to a mutex pointer --- agent/xds/delta_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/xds/delta_test.go b/agent/xds/delta_test.go index fcd0d86e4eb3..98a4c57e79c6 100644 --- a/agent/xds/delta_test.go +++ b/agent/xds/delta_test.go @@ -1059,7 +1059,7 @@ func TestServer_DeltaAggregatedResources_v3_ACLEnforcement(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var stopped bool - var lock sync.RWMutex + lock := &sync.RWMutex{} defer func() { lock.Lock()