1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:34:42 -07:00

net/http: re-enable test

Now with a bit more paranoia and lower number of requests
to keep it under the default OS X 256 fd limit.

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5659051
This commit is contained in:
Brad Fitzpatrick 2012-02-14 15:26:09 +11:00
parent 55a54691f9
commit c2a1157680

View File

@ -635,9 +635,6 @@ func TestTransportGzipRecursive(t *testing.T) {
// tests that persistent goroutine connections shut down when no longer desired. // tests that persistent goroutine connections shut down when no longer desired.
func TestTransportPersistConnLeak(t *testing.T) { func TestTransportPersistConnLeak(t *testing.T) {
t.Logf("test is buggy - appears to leak fds")
return
gotReqCh := make(chan bool) gotReqCh := make(chan bool)
unblockCh := make(chan bool) unblockCh := make(chan bool)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
@ -653,12 +650,17 @@ func TestTransportPersistConnLeak(t *testing.T) {
n0 := runtime.Goroutines() n0 := runtime.Goroutines()
const numReq = 100 const numReq = 25
didReqCh := make(chan bool) didReqCh := make(chan bool)
for i := 0; i < numReq; i++ { for i := 0; i < numReq; i++ {
go func() { go func() {
c.Get(ts.URL) res, err := c.Get(ts.URL)
didReqCh <- true didReqCh <- true
if err != nil {
t.Errorf("client fetch error: %v", err)
return
}
res.Body.Close()
}() }()
} }
@ -679,6 +681,7 @@ func TestTransportPersistConnLeak(t *testing.T) {
<-didReqCh <-didReqCh
} }
tr.CloseIdleConnections()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
runtime.GC() runtime.GC()
runtime.GC() // even more. runtime.GC() // even more.
@ -686,13 +689,11 @@ func TestTransportPersistConnLeak(t *testing.T) {
growth := nfinal - n0 growth := nfinal - n0
// We expect 5 extra goroutines, empirically. That number is at least // We expect 0 or 1 extra goroutine, empirically. Allow up to 5.
// DefaultMaxIdleConnsPerHost * 2 (one reader goroutine, one writer), // Previously we were leaking one per numReq.
// and something else. t.Logf("goroutine growth: %d -> %d -> %d (delta: %d)", n0, nhigh, nfinal, growth)
expectedGoroutineGrowth := DefaultMaxIdleConnsPerHost*2 + 1 if int(growth) > 5 {
t.Error("too many new goroutines")
if int(growth) > expectedGoroutineGrowth*2 {
t.Errorf("goroutine growth: %d -> %d -> %d (delta: %d)", n0, nhigh, nfinal, growth)
} }
} }