Export_is408Message = is408Message
)
-const MaxWriteWaitBeforeConnReuse = maxWriteWaitBeforeConnReuse
+var MaxWriteWaitBeforeConnReuse = &maxWriteWaitBeforeConnReuse
func init() {
// We only want to pay for this cost during testing.
var quietLog = log.New(io.Discard, "", 0)
func TestMain(m *testing.M) {
+ *http.MaxWriteWaitBeforeConnReuse = 60 * time.Minute
v := m.Run()
if v == 0 && goroutineLeaked() {
os.Exit(1)
// maxWriteWaitBeforeConnReuse is how long the a Transport RoundTrip
// will wait to see the Request's Body.Write result after getting a
// response from the server. See comments in (*persistConn).wroteRequest.
-const maxWriteWaitBeforeConnReuse = 50 * time.Millisecond
+//
+// In tests, we set this to a large value to avoid flakiness from inconsistent
+// recycling of connections.
+var maxWriteWaitBeforeConnReuse = 50 * time.Millisecond
// wroteRequest is a check before recycling a connection that the previous write
// (from writeLoop above) happened and was successful.
// questionable state.
// golang.org/issue/7569
func TestTransportNoReuseAfterEarlyResponse(t *testing.T) {
- run(t, testTransportNoReuseAfterEarlyResponse, []testMode{http1Mode})
+ run(t, testTransportNoReuseAfterEarlyResponse, []testMode{http1Mode}, testNotParallel)
}
func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) {
+ defer func(d time.Duration) {
+ *MaxWriteWaitBeforeConnReuse = d
+ }(*MaxWriteWaitBeforeConnReuse)
+ *MaxWriteWaitBeforeConnReuse = 10 * time.Millisecond
var sconn struct {
sync.Mutex
c net.Conn
req := tc.req()
res, err := c.Do(req)
if err != nil {
- if time.Since(t0) < MaxWriteWaitBeforeConnReuse/2 {
+ if time.Since(t0) < *MaxWriteWaitBeforeConnReuse/2 {
mu.Lock()
got := logbuf.String()
mu.Unlock()
t.Fatalf("i=%d: Do = %v; log:\n%s", i, err, got)
}
- t.Skipf("connection likely wasn't recycled within %d, interfering with actual test; skipping", MaxWriteWaitBeforeConnReuse)
+ t.Skipf("connection likely wasn't recycled within %d, interfering with actual test; skipping", *MaxWriteWaitBeforeConnReuse)
}
res.Body.Close()
if res.Request != req {