]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: run TestRequestWriteTransport with fake time to avoid flakes
authorDamien Neil <dneil@google.com>
Thu, 9 Oct 2025 22:25:30 +0000 (15:25 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 10 Oct 2025 15:39:10 +0000 (08:39 -0700)
This test verifies whether or not we use the chunked encoding when
sending a request with a body like io.NopCloser(strings.NewReader("")).
This depends on whether the transport can read a single byte from the
request body within 200ms, which is flaky on very slow builders.

Use fake time to avoid flakes.

Fixes #52575

Change-Id: Ie11a58ac6bc18d43af1423827887e804242dee30
Reviewed-on: https://go-review.googlesource.com/c/go/+/710737
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/net/http/requestwrite_test.go

index 380ae9dec3244d1d43b3bc07e79a36629159b8b7..8b097cd5e15d1f6f4e5ddb68095c9c322b18ab8f 100644 (file)
@@ -15,6 +15,7 @@ import (
        "strings"
        "testing"
        "testing/iotest"
+       "testing/synctest"
        "time"
 )
 
@@ -667,6 +668,13 @@ func TestRequestWrite(t *testing.T) {
 func TestRequestWriteTransport(t *testing.T) {
        t.Parallel()
 
+       // Run this test in a synctest bubble, since it relies on the transport
+       // successfully probing the request body within 200ms
+       // (see transferWriter.probeRequestBody).
+       // This occasionally flakes on slow builders (#52575) if we don't use a fake clock.
+       synctest.Test(t, testRequestWriteTransport)
+}
+func testRequestWriteTransport(t *testing.T) {
        matchSubstr := func(substr string) func(string) error {
                return func(written string) error {
                        if !strings.Contains(written, substr) {