Skip to content

Commit

Permalink
New attempt to fix this test. Could it be aborted connections?
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Oct 9, 2024
1 parent 87645c1 commit 5d8c8e8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions crypto/tls/test/tls_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -136,19 +138,22 @@ 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)
if err == nil {
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
}
Expand All @@ -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
Expand Down Expand Up @@ -193,10 +199,7 @@ func newIntegrationClientServer(
assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, resp.Status)
}
})

}

serv.Shutdown()
}

func TestServerWithoutTlsEnabled(t *testing.T) {
Expand Down

0 comments on commit 5d8c8e8

Please sign in to comment.