Clean shutdown of client integration tests

This commit is contained in:
Wojciech Tyczyński 2022-07-18 21:13:33 +02:00
parent e9e494e14a
commit f673c262bd
2 changed files with 8 additions and 1 deletions

View File

@ -36,6 +36,11 @@ type tlsTransportCache struct {
transports map[tlsCacheKey]*http.Transport
}
// DialerStopCh is stop channel that is passed down to dynamic cert dialer.
// It's exposed as variable for testing purposes to avoid testing for goroutine
// leakages.
var DialerStopCh = wait.NeverStop
const idleConnsPerHost = 25
var tlsCache = &tlsTransportCache{transports: make(map[tlsCacheKey]*http.Transport)}
@ -101,7 +106,7 @@ func (c *tlsTransportCache) get(config *Config) (http.RoundTripper, error) {
dynamicCertDialer := certRotatingDialer(tlsConfig.GetClientCertificate, dial)
tlsConfig.GetClientCertificate = dynamicCertDialer.GetClientCertificate
dial = dynamicCertDialer.connDialer.DialContext
go dynamicCertDialer.Run(wait.NeverStop)
go dynamicCertDialer.Run(DialerStopCh)
}
proxy := http.ProxyFromEnvironment

View File

@ -46,6 +46,7 @@ func TestCertRotation(t *testing.T) {
defer close(stopCh)
transport.CertCallbackRefreshDuration = 1 * time.Second
transport.DialerStopCh = stopCh
certDir := os.TempDir()
clientCAFilename, clientSigningCert, clientSigningKey := writeCACertFiles(t, certDir)
@ -103,6 +104,7 @@ func TestCertRotationContinuousRequests(t *testing.T) {
defer close(stopCh)
transport.CertCallbackRefreshDuration = 1 * time.Second
transport.DialerStopCh = stopCh
certDir := os.TempDir()
clientCAFilename, clientSigningCert, clientSigningKey := writeCACertFiles(t, certDir)