1
0
mirror of https://github.com/golang/go synced 2024-11-24 20:30:14 -07:00

net: deflake TestDialerDualStackFDLeak

We need to stop the mock listener certainly for preventing it from
pulling up pending connections during measurement.

Fixes #14223.

Change-Id: Ia40db01d1262963697b83ca867563dec77d772e3
Reviewed-on: https://go-review.googlesource.com/19246
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Mikio Hara 2016-02-19 17:41:44 +09:00
parent e6d6ad47f5
commit 9194421eed

View File

@ -176,6 +176,7 @@ func TestDialerDualStackFDLeak(t *testing.T) {
t.Skip("both IPv4 and IPv6 are required")
}
before := sw.Sockets()
origTestHookLookupIP := testHookLookupIP
defer func() { testHookLookupIP = origTestHookLookupIP }()
testHookLookupIP = lookupLocalhost
@ -195,17 +196,15 @@ func TestDialerDualStackFDLeak(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer dss.teardown()
if err := dss.buildup(handler); err != nil {
dss.teardown()
t.Fatal(err)
}
before := sw.Sockets()
const T = 100 * time.Millisecond
const N = 10
var wg sync.WaitGroup
wg.Add(N)
d := &Dialer{DualStack: true, Timeout: T}
d := &Dialer{DualStack: true, Timeout: 100 * time.Millisecond}
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
@ -218,7 +217,7 @@ func TestDialerDualStackFDLeak(t *testing.T) {
}()
}
wg.Wait()
time.Sleep(2 * T) // wait for the dial racers to stop
dss.teardown()
after := sw.Sockets()
if len(after) != len(before) {
t.Errorf("got %d; want %d", len(after), len(before))