From 5c836f2aa965d09dde66668c25b978effa6b75c9 Mon Sep 17 00:00:00 2001 From: John Eikenberry Date: Fri, 3 Feb 2023 22:09:34 +0000 Subject: [PATCH] fix goroutine leak in renew testing (#16142) fix goroutine leak in renew testing Test overwrote the stopWatcher() function variable for the test without keeping and calling the original value. The original value is the function that stops the goroutine... so it needs to be called. --- agent/connect/ca/provider_vault_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/connect/ca/provider_vault_test.go b/agent/connect/ca/provider_vault_test.go index cac4a4bf73..4fbeb51171 100644 --- a/agent/connect/ca/provider_vault_test.go +++ b/agent/connect/ca/provider_vault_test.go @@ -198,7 +198,6 @@ func TestVaultCAProvider_Configure(t *testing.T) { "IntermediatePKIPath": "pki-intermediate/", }, expectedValue: func(t *testing.T, v *VaultProvider) { - h := v.client.Headers() require.Equal(t, "ns1", h.Get(vaultconst.NamespaceHeaderName)) }, @@ -306,9 +305,13 @@ func TestVaultCAProvider_RenewTokenStopWatcherOnConfigure(t *testing.T) { "IntermediatePKIPath": "pki-intermediate/", }) - var gotStopped = uint32(0) + // overwrite stopWatcher to set flag on stop for testing + // be sure that original stopWatcher gets called to avoid goroutine leak + gotStopped := uint32(0) + realStop := provider.stopWatcher provider.stopWatcher = func() { atomic.StoreUint32(&gotStopped, 1) + realStop() } // Check the last renewal time.