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.
This commit is contained in:
John Eikenberry 2023-02-03 22:09:34 +00:00 committed by GitHub
parent f1d18f1a9b
commit 5c836f2aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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.