mirror of
https://github.com/golang/go
synced 2024-11-24 22:47:58 -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:
parent
e6d6ad47f5
commit
9194421eed
@ -176,6 +176,7 @@ func TestDialerDualStackFDLeak(t *testing.T) {
|
|||||||
t.Skip("both IPv4 and IPv6 are required")
|
t.Skip("both IPv4 and IPv6 are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before := sw.Sockets()
|
||||||
origTestHookLookupIP := testHookLookupIP
|
origTestHookLookupIP := testHookLookupIP
|
||||||
defer func() { testHookLookupIP = origTestHookLookupIP }()
|
defer func() { testHookLookupIP = origTestHookLookupIP }()
|
||||||
testHookLookupIP = lookupLocalhost
|
testHookLookupIP = lookupLocalhost
|
||||||
@ -195,17 +196,15 @@ func TestDialerDualStackFDLeak(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer dss.teardown()
|
|
||||||
if err := dss.buildup(handler); err != nil {
|
if err := dss.buildup(handler); err != nil {
|
||||||
|
dss.teardown()
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
before := sw.Sockets()
|
|
||||||
const T = 100 * time.Millisecond
|
|
||||||
const N = 10
|
const N = 10
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(N)
|
wg.Add(N)
|
||||||
d := &Dialer{DualStack: true, Timeout: T}
|
d := &Dialer{DualStack: true, Timeout: 100 * time.Millisecond}
|
||||||
for i := 0; i < N; i++ {
|
for i := 0; i < N; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
@ -218,7 +217,7 @@ func TestDialerDualStackFDLeak(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
time.Sleep(2 * T) // wait for the dial racers to stop
|
dss.teardown()
|
||||||
after := sw.Sockets()
|
after := sw.Sockets()
|
||||||
if len(after) != len(before) {
|
if len(after) != len(before) {
|
||||||
t.Errorf("got %d; want %d", len(after), len(before))
|
t.Errorf("got %d; want %d", len(after), len(before))
|
||||||
|
Loading…
Reference in New Issue
Block a user