Commit 7e8bc474 authored by Fabrizio Milo's avatar Fabrizio Milo Committed by Brad Fitzpatrick

net/http: fix flaky test

Prevent idle transport on race condition.

Fixes #7847

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/96230044
parent fb392867
...@@ -1553,8 +1553,10 @@ func TestTransportSocketLateBinding(t *testing.T) { ...@@ -1553,8 +1553,10 @@ func TestTransportSocketLateBinding(t *testing.T) {
dialGate := make(chan bool, 1) dialGate := make(chan bool, 1)
tr := &Transport{ tr := &Transport{
Dial: func(n, addr string) (net.Conn, error) { Dial: func(n, addr string) (net.Conn, error) {
<-dialGate if <-dialGate {
return net.Dial(n, addr) return net.Dial(n, addr)
}
return nil, errors.New("manually closed")
}, },
DisableKeepAlives: false, DisableKeepAlives: false,
} }
...@@ -1589,7 +1591,7 @@ func TestTransportSocketLateBinding(t *testing.T) { ...@@ -1589,7 +1591,7 @@ func TestTransportSocketLateBinding(t *testing.T) {
t.Fatalf("/foo came from conn %q; /bar came from %q instead", fooAddr, barAddr) t.Fatalf("/foo came from conn %q; /bar came from %q instead", fooAddr, barAddr)
} }
barRes.Body.Close() barRes.Body.Close()
dialGate <- true dialGate <- false
} }
// Issue 2184 // Issue 2184
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment