From 98f17660c8b1bb9bf5154abd7f927d412e00f584 Mon Sep 17 00:00:00 2001 From: k2safe Date: Tue, 22 Sep 2026 23:35:23 +0800 Subject: [PATCH] fix: keep HTTP2 soak context through response body --- transport/http2/soak_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/transport/http2/soak_test.go b/transport/http2/soak_test.go index a7d85ae..6c1e1a4 100644 --- a/transport/http2/soak_test.go +++ b/transport/http2/soak_test.go @@ -91,20 +91,28 @@ func TestTLSSoak(t *testing.T) { method = http.MethodPost body = &repeatingReader{remaining: 64 << 10} } - request, err := http.NewRequestWithContext(context.Background(), method, "https://"+listener.Addr().String()+path, body) + requestContext, cancelRequest := context.WithTimeout(context.Background(), 2*time.Second) + request, err := http.NewRequestWithContext(requestContext, method, "https://"+listener.Addr().String()+path, body) if err != nil { + cancelRequest() failures.Add(1) continue } response, err := client.Do(request) if err != nil { - failures.Add(1) + cancelRequest() + if time.Now().Before(deadline) { + failures.Add(1) + } continue } _, readErr := io.Copy(io.Discard, response.Body) response.Body.Close() + cancelRequest() if readErr != nil || response.StatusCode != http.StatusOK { - failures.Add(1) + if time.Now().Before(deadline) { + failures.Add(1) + } continue } requests.Add(1)