From 5d8c8e85fac816b16305ba5f647b73749de8108b Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Wed, 9 Oct 2024 09:34:15 -0400 Subject: [PATCH] New attempt to fix this test. Could it be aborted connections? --- crypto/tls/test/tls_integration_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crypto/tls/test/tls_integration_test.go b/crypto/tls/test/tls_integration_test.go index b658603d0..6cafa2e8c 100644 --- a/crypto/tls/test/tls_integration_test.go +++ b/crypto/tls/test/tls_integration_test.go @@ -17,6 +17,7 @@ import ( "time" "github.com/gogo/status" + "github.com/hashicorp/go-cleanhttp" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -103,6 +104,7 @@ func newIntegrationClientServer( serv, err := server.New(cfg) require.NoError(t, err) + defer serv.Shutdown() serv.HTTP.HandleFunc("/hello", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "OK") @@ -136,12 +138,14 @@ func newIntegrationClientServer( grpcHost := net.JoinHostPort("localhost", strconv.Itoa(grpcAddr.Port)) for _, tc := range tcs { - tlsClientConfig, err := tc.tlsConfig.GetTLSConfig() - require.NoError(t, err) - // HTTP t.Run("HTTP/"+tc.name, func(t *testing.T) { - transport := &http.Transport{TLSClientConfig: tlsClientConfig, MaxIdleConnsPerHost: 100} // DefaultMaxIdleConnsPerHost is 2 + tlsClientConfig, err := tc.tlsConfig.GetTLSConfig() + require.NoError(t, err) + + transport := cleanhttp.DefaultTransport() + transport.TLSClientConfig = tlsClientConfig + transport.TLSHandshakeTimeout = 500 * time.Millisecond client := &http.Client{Transport: transport} resp, err := client.Get(httpURL) @@ -149,6 +153,7 @@ func newIntegrationClientServer( defer resp.Body.Close() } if tc.httpExpectError != nil { + time.Sleep(500 * time.Millisecond) // This makes sure that the server has time to close the connection tc.httpExpectError(t, err) return } @@ -160,6 +165,7 @@ func newIntegrationClientServer( assert.NoError(t, err, tc.name) assert.Equal(t, []byte("OK"), body, tc.name) + time.Sleep(500 * time.Millisecond) // This makes sure that the server has time to close the connection }) // GRPC @@ -193,10 +199,7 @@ func newIntegrationClientServer( assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, resp.Status) } }) - } - - serv.Shutdown() } func TestServerWithoutTlsEnabled(t *testing.T) {