1
0
mirror of https://github.com/golang/go synced 2024-11-12 06:20:22 -07:00

net/http: unflake TestTransportConcurrency

Fixes #5005

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8127043
This commit is contained in:
Brad Fitzpatrick 2013-03-28 18:36:06 -07:00
parent f38811979c
commit 68130a07af

View File

@ -950,14 +950,28 @@ func TestTransportConcurrency(t *testing.T) {
fmt.Fprintf(w, "%v", r.FormValue("echo"))
}))
defer ts.Close()
tr := &Transport{}
var wg sync.WaitGroup
wg.Add(numReqs)
tr := &Transport{
Dial: func(netw, addr string) (c net.Conn, err error) {
// Due to the Transport's "socket late
// binding" (see idleConnCh in transport.go),
// the numReqs HTTP requests below can finish
// with a dial still outstanding. So count
// our dials as work too so the leak checker
// doesn't complain at us.
wg.Add(1)
defer wg.Done()
return net.Dial(netw, addr)
},
}
defer tr.CloseIdleConnections()
c := &Client{Transport: tr}
reqs := make(chan string)
defer close(reqs)
var wg sync.WaitGroup
wg.Add(numReqs)
for i := 0; i < maxProcs*2; i++ {
go func() {
for req := range reqs {