From 3844cac47a727a0b9cd0ff3a9986ec035bcf26ad Mon Sep 17 00:00:00 2001 From: Seth Back Date: Wed, 6 Sep 2023 14:05:05 -0700 Subject: [PATCH] Add HTTP Shutdown Timeout (#151) * add shutdown timeout * re-enable helper --- surveyor/conn_pool_test.go | 2 ++ surveyor/surveyor.go | 4 +++- surveyor/surveyor_test.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/surveyor/conn_pool_test.go b/surveyor/conn_pool_test.go index 733e447..f0df7a3 100644 --- a/surveyor/conn_pool_test.go +++ b/surveyor/conn_pool_test.go @@ -13,6 +13,8 @@ import ( ) func TestConnPool(t *testing.T) { + t.Parallel() + s := natsservertest.RunRandClientPortServer() defer s.Shutdown() o1 := &natsContext{ diff --git a/surveyor/surveyor.go b/surveyor/surveyor.go index 0bd1537..17d8ee8 100644 --- a/surveyor/surveyor.go +++ b/surveyor/surveyor.go @@ -497,7 +497,9 @@ func (s *Surveyor) Stop() { } if s.httpServer != nil { - _ = s.httpServer.Shutdown(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + _ = s.httpServer.Shutdown(ctx) s.httpServer = nil } diff --git a/surveyor/surveyor_test.go b/surveyor/surveyor_test.go index 43defa2..b9a03ca 100644 --- a/surveyor/surveyor_test.go +++ b/surveyor/surveyor_test.go @@ -45,7 +45,7 @@ func httpGetSecure(url string) (*http.Response, error) { return nil, err } transport := &http.Transport{TLSClientConfig: tlsConfig} - httpClient := &http.Client{Transport: transport, Timeout: 30 * time.Second} + httpClient := &http.Client{Transport: transport, Timeout: 3 * time.Second} return httpClient.Get(url) } @@ -70,7 +70,7 @@ func parseTLSConfig(certFile, keyFile, caFile string) (*tls.Config, error) { } func httpGet(url string) (*http.Response, error) { - httpClient := &http.Client{Timeout: 30 * time.Second} + httpClient := &http.Client{Timeout: 3 * time.Second} return httpClient.Get(url) }