]> Cypherpunks repositories - gostls13.git/commitdiff
net: deflake TestDialerDualStackFDLeak
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 19 Feb 2016 08:41:44 +0000 (17:41 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Sun, 21 Feb 2016 02:54:12 +0000 (02:54 +0000)
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>
src/net/dial_test.go

index 2311b108241d3d552d4c034d7370f20e68f59392..1a9dfb26d3dc58e8f27358fa860b7a4cf250b5b8 100644 (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))