mirror of
https://github.com/golang/go
synced 2024-11-24 01:30:10 -07:00
net/http: adaptive wait time in PersistConnLeak tests
In tests TransportPersistConnLeak and TransportPersistConnLeakShortBody, there's a fixed wait time (100ms and 400ms respectively) to allow goroutines to exit after CloseIdleConnections is called. This is sometimes too short on a slow host running many simultaneous tests. This CL replaces the fixed sleep in each test with a sequence of shorter sleeps, testing the number of remaining goroutines until it reaches the threshold or an overall time limit of 500ms expires. This prevents some failures in the plan9_arm builder, while reducing the test time on faster machines. Fixes #14887 Change-Id: Ia5c871062df139e2667cdfb2ce8283e135435318 Reviewed-on: https://go-review.googlesource.com/20922 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
a7a199947a
commit
34f0c0b3de
@ -968,6 +968,17 @@ func TestTransportGzipShort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait until number of goroutines is no greater than nmax, or time out.
|
||||||
|
func waitNumGoroutine(nmax int) int {
|
||||||
|
nfinal := runtime.NumGoroutine()
|
||||||
|
for ntries := 10; ntries > 0 && nfinal > nmax; ntries-- {
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
runtime.GC()
|
||||||
|
nfinal = runtime.NumGoroutine()
|
||||||
|
}
|
||||||
|
return nfinal
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
setParallel(t)
|
setParallel(t)
|
||||||
@ -1019,10 +1030,7 @@ func TestTransportPersistConnLeak(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tr.CloseIdleConnections()
|
tr.CloseIdleConnections()
|
||||||
time.Sleep(100 * time.Millisecond)
|
nfinal := waitNumGoroutine(n0 + 5)
|
||||||
runtime.GC()
|
|
||||||
runtime.GC() // even more.
|
|
||||||
nfinal := runtime.NumGoroutine()
|
|
||||||
|
|
||||||
growth := nfinal - n0
|
growth := nfinal - n0
|
||||||
|
|
||||||
@ -1061,9 +1069,7 @@ func TestTransportPersistConnLeakShortBody(t *testing.T) {
|
|||||||
}
|
}
|
||||||
nhigh := runtime.NumGoroutine()
|
nhigh := runtime.NumGoroutine()
|
||||||
tr.CloseIdleConnections()
|
tr.CloseIdleConnections()
|
||||||
time.Sleep(400 * time.Millisecond)
|
nfinal := waitNumGoroutine(n0 + 5)
|
||||||
runtime.GC()
|
|
||||||
nfinal := runtime.NumGoroutine()
|
|
||||||
|
|
||||||
growth := nfinal - n0
|
growth := nfinal - n0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user