mirror of https://github.com/status-im/consul.git
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:
parent
f1d18f1a9b
commit
5c836f2aa9
|
@ -198,7 +198,6 @@ func TestVaultCAProvider_Configure(t *testing.T) {
|
||||||
"IntermediatePKIPath": "pki-intermediate/",
|
"IntermediatePKIPath": "pki-intermediate/",
|
||||||
},
|
},
|
||||||
expectedValue: func(t *testing.T, v *VaultProvider) {
|
expectedValue: func(t *testing.T, v *VaultProvider) {
|
||||||
|
|
||||||
h := v.client.Headers()
|
h := v.client.Headers()
|
||||||
require.Equal(t, "ns1", h.Get(vaultconst.NamespaceHeaderName))
|
require.Equal(t, "ns1", h.Get(vaultconst.NamespaceHeaderName))
|
||||||
},
|
},
|
||||||
|
@ -306,9 +305,13 @@ func TestVaultCAProvider_RenewTokenStopWatcherOnConfigure(t *testing.T) {
|
||||||
"IntermediatePKIPath": "pki-intermediate/",
|
"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() {
|
provider.stopWatcher = func() {
|
||||||
atomic.StoreUint32(&gotStopped, 1)
|
atomic.StoreUint32(&gotStopped, 1)
|
||||||
|
realStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the last renewal time.
|
// Check the last renewal time.
|
||||||
|
|
Loading…
Reference in New Issue