fix: keep HTTP2 soak context through response body

This commit is contained in:
2026-09-22 23:35:23 +08:00
parent c8660026ce
commit 98f17660c8

View File

@@ -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)