mirror of https://github.com/golang/go.git
net: make TestDialFailPDLeak shorter
Reduces a number of trials but it still can detect memory leak when we make blunders in runtime-integarted network poller work, like just forgetting to call runtime_pollClose in code paths. Also disables the test on windows/386. R=alex.brainman, r CC=golang-dev https://golang.org/cl/13022046
This commit is contained in:
parent
e38eddbfe4
commit
81737a9a51
|
|
@ -431,9 +431,15 @@ func TestDialFailPDLeak(t *testing.T) {
|
|||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
if runtime.GOOS == "windows" && runtime.GOARCH == "386" {
|
||||
// Just skip the test because it takes too long.
|
||||
t.Skipf("skipping test on %q/%q", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
const loops = 10
|
||||
const count = 20000
|
||||
// 500 is enough to turn over the chunk of pollcache.
|
||||
// See allocPollDesc in runtime/netpoll.goc.
|
||||
const count = 500
|
||||
var old runtime.MemStats // used by sysdelta
|
||||
runtime.ReadMemStats(&old)
|
||||
sysdelta := func() uint64 {
|
||||
|
|
@ -446,13 +452,20 @@ func TestDialFailPDLeak(t *testing.T) {
|
|||
d := &Dialer{Timeout: time.Nanosecond} // don't bother TCP with handshaking
|
||||
failcount := 0
|
||||
for i := 0; i < loops; i++ {
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < count; i++ {
|
||||
conn, err := d.Dial("tcp", "127.0.0.1:1")
|
||||
if err == nil {
|
||||
t.Error("dial should not succeed")
|
||||
conn.Close()
|
||||
t.FailNow()
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if c, err := d.Dial("tcp", "127.0.0.1:1"); err == nil {
|
||||
t.Error("dial should not succeed")
|
||||
c.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
if t.Failed() {
|
||||
t.FailNow()
|
||||
}
|
||||
if delta := sysdelta(); delta > 0 {
|
||||
failcount++
|
||||
|
|
|
|||
Loading…
Reference in New Issue