From d98d4dc1199bd726d632c28ee62c536bbf562706 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 4 Oct 2026 03:47:32 +0000 Subject: [PATCH] Test a fetch whose context ends waiting for a shared connection A fetch from a host with nothing open waits for the connection shared by all hosts, and its context ends long before the wait timeout; once every response is closed, no semaphore may be left in hostSems. Model: opus-5-5 --- .../max_connections_internal_test.go | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/httpfetcher/max_connections_internal_test.go b/internal/httpfetcher/max_connections_internal_test.go index a19437f..a776460 100644 --- a/internal/httpfetcher/max_connections_internal_test.go +++ b/internal/httpfetcher/max_connections_internal_test.go @@ -153,9 +153,11 @@ func TestFetchRemovesIdleHostSemaphores(t *testing.T) { } // TestFetchRemovesHostSemaphoreWhenNoConnection checks that a fetch that -// ends without a connection leaves no semaphore behind, both when it is -// refused after waiting for a connection shared by all hosts and when its -// context ends while it waits for its host's slot. +// ends without a connection leaves no semaphore behind: when it is refused +// after waiting for a connection shared by all hosts, when its context ends +// while it waits for its host's slot, and when its context ends while it +// waits for a connection shared by all hosts, long before the 10 second +// wait timeout. func TestFetchRemovesHostSemaphoreWhenNoConnection(t *testing.T) { t.Parallel() @@ -188,6 +190,18 @@ func TestFetchRemovesHostSemaphoreWhenNoConnection(t *testing.T) { "want context.DeadlineExceeded", err) } + // Back to the 10 second wait, so the next fetch's context ends first. + f.connectionWaitTimeout = ConnectionWaitTimeout + + ctx, cancel = context.WithTimeout(t.Context(), 100*time.Millisecond) + defer cancel() + + _, err = f.Fetch(ctx, imageURLOnPort(83)) + if !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("Fetch() from a host with nothing open: error = %v, "+ + "want context.DeadlineExceeded", err) + } + err = open.Content.Close() if err != nil { t.Fatalf("close first body: %v", err)