diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 6c66ee3..b7fcf42 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -122,13 +122,17 @@ func testConfig(t *testing.T, relay string) config.Config { return c } +// client opens one connection per request: a pooled connection the transport dialed and never +// used would hold an HTTP server's graceful shutdown for 5 s. +var client = &http.Client{Transport: &http.Transport{DisableKeepAlives: true}} + func call(t *testing.T, a *App, method, path, body, token string) int { t.Helper() req, _ := http.NewRequest(method, "http://"+a.APIAddr+path, strings.NewReader(body)) if token != "" { req.Header.Set("Authorization", "Bearer "+token) } - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) if err != nil { t.Fatal(err) } @@ -139,7 +143,7 @@ func call(t *testing.T, a *App, method, path, body, token string) int { func fetch(t *testing.T, method, url string) (int, string) { t.Helper() req, _ := http.NewRequest(method, url, nil) - resp, err := http.DefaultClient.Do(req) + resp, err := client.Do(req) if err != nil { t.Fatal(err) } @@ -466,8 +470,6 @@ func TestCloseLetsAnLMTPDeliveryInFlightFinish(t *testing.T) { } call(t, a, "POST", "/api/v1/lists", `{"name":"dev","domain":"example.org"}`, "tok") call(t, a, "POST", "/api/v1/lists/1/members", `{"address":"alice@example.com"}`, "tok") - // A connection the HTTP client opened and never used would hold the API's shutdown for 5 s. - http.DefaultClient.CloseIdleConnections() conn, err := net.Dial("tcp", a.LMTPAddr) if err != nil {