From 79ff1355c2251b7030bbf201d4f2e961d3d2fd9e 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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crypto/tls/test/tls_integration_test.go b/crypto/tls/test/tls_integration_test.go index b658603d0..414eb2fd5 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,13 @@ 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 client := &http.Client{Transport: transport} resp, err := client.Get(httpURL) @@ -150,6 +153,7 @@ func newIntegrationClientServer( } if tc.httpExpectError != nil { tc.httpExpectError(t, err) + time.Sleep(500 * time.Millisecond) // This prevents test flakiness: See https://go-review.googlesource.com/c/go/+/527196/6/src/net/http/server.go return } if err != nil { @@ -193,10 +197,7 @@ func newIntegrationClientServer( assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, resp.Status) } }) - } - - serv.Shutdown() } func TestServerWithoutTlsEnabled(t *testing.T) {