From cb992b35fd92236dcf63cf498e0204200f422307 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:39:45 +1000 Subject: [PATCH] test(site): isolate httptest server clients (#27769) Closes ENG-3094 Closes https://github.com/coder/internal/issues/582 The flake was caused by `TestServingBin` using `&http.Client{}`, which shares `http.DefaultTransport` with every parallel test in the binary. When another `httptest.Server` closed, it called `CloseIdleConnections` on the shared transport and could break our request. I couldn't replicate this locally, but the error comes directly from that cleanup path. The fix is just to use each test server's `Client()`, which has its own transport. I've also updated `TestServingFiles`, as it had the same setup. --- site/site_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/site_test.go b/site/site_test.go index bb66ecaf9a..3aceee175e 100644 --- a/site/site_test.go +++ b/site/site_test.go @@ -576,7 +576,7 @@ func TestServingFiles(t *testing.T) { require.NoError(t, err) srv := httptest.NewServer(handler) defer srv.Close() - client := &http.Client{} + client := srv.Client() // Create a context ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitShort) @@ -865,7 +865,7 @@ func TestServingBin(t *testing.T) { compressor := middleware.NewCompressor(1, "text/*", "application/*") srv := httptest.NewServer(compressor.Handler(handler)) defer srv.Close() - client := &http.Client{} + client := srv.Client() // Create a context ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitShort)