From 9194421eedfd64d2d71e66cbf060d19502610c30 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Fri, 19 Feb 2016 17:41:44 +0900 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/dial_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/net/dial_test.go b/src/net/dial_test.go index 2311b108241..1a9dfb26d3d 100644 --- a/src/net/dial_test.go +++ b/src/net/dial_test.go @@ -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))