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
This commit is contained in:
Fabrizio Milo 2014-05-12 09:37:36 -07:00 committed by Brad Fitzpatrick
parent fb392867ae
commit 7e8bc474db
1 changed files with 5 additions and 3 deletions

View File

@ -1553,8 +1553,10 @@ func TestTransportSocketLateBinding(t *testing.T) {
dialGate := make(chan bool, 1)
tr := &Transport{
Dial: func(n, addr string) (net.Conn, error) {
<-dialGate
return net.Dial(n, addr)
if <-dialGate {
return net.Dial(n, addr)
}
return nil, errors.New("manually closed")
},
DisableKeepAlives: false,
}
@ -1589,7 +1591,7 @@ func TestTransportSocketLateBinding(t *testing.T) {
t.Fatalf("/foo came from conn %q; /bar came from %q instead", fooAddr, barAddr)
}
barRes.Body.Close()
dialGate <- true
dialGate <- false
}
// Issue 2184