net/http: run TestRequestWriteTransport with fake time to avoid flakes

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>
This commit is contained in:
Damien Neil 2025-10-09 15:25:30 -07:00 committed by Gopher Robot
parent c53cb642de
commit 5368e77429

View 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) {