From f439e07b1b43d7b4cdbd6db623cedac9735189c1 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Wed, 18 Dec 2013 13:05:47 +0900 Subject: [PATCH] net: make TestDNSThreadLimit execute at the end of tests Because TestDNSThreadLimit consumes tons of file descriptors and makes other tests flaky when CGO_ENABLE=0 or being with netgo tag. Fixes #6580. R=golang-dev, bradfitz, adg, minux.ma CC=golang-dev https://golang.org/cl/14639044 --- src/pkg/net/dialgoogle_test.go | 24 ------------------------ src/pkg/net/z_last_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 src/pkg/net/z_last_test.go diff --git a/src/pkg/net/dialgoogle_test.go b/src/pkg/net/dialgoogle_test.go index b4ebad0e0dc..79d150f8aad 100644 --- a/src/pkg/net/dialgoogle_test.go +++ b/src/pkg/net/dialgoogle_test.go @@ -107,30 +107,6 @@ var googleaddrsipv4 = []string{ "[0:0:0:0:0:ffff::%d.%d.%d.%d]:80", } -func TestDNSThreadLimit(t *testing.T) { - if testing.Short() || !*testExternal { - t.Skip("skipping test to avoid external network") - } - - const N = 10000 - c := make(chan int, N) - for i := 0; i < N; i++ { - go func(i int) { - LookupIP(fmt.Sprintf("%d.net-test.golang.org", i)) - c <- 1 - }(i) - } - // Don't bother waiting for the stragglers; stop at 0.9 N. - for i := 0; i < N*9/10; i++ { - if i%100 == 0 { - //println("TestDNSThreadLimit:", i) - } - <-c - } - - // If we're still here, it worked. -} - func TestDialGoogleIPv4(t *testing.T) { if testing.Short() || !*testExternal { t.Skip("skipping test to avoid external network") diff --git a/src/pkg/net/z_last_test.go b/src/pkg/net/z_last_test.go new file mode 100644 index 00000000000..bb00f110fe9 --- /dev/null +++ b/src/pkg/net/z_last_test.go @@ -0,0 +1,34 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +import ( + "fmt" + "testing" +) + +func TestDNSThreadLimit(t *testing.T) { + if testing.Short() || !*testExternal { + t.Skip("skipping test to avoid external network") + } + + const N = 10000 + c := make(chan int, N) + for i := 0; i < N; i++ { + go func(i int) { + LookupIP(fmt.Sprintf("%d.net-test.golang.org", i)) + c <- 1 + }(i) + } + // Don't bother waiting for the stragglers; stop at 0.9 N. + for i := 0; i < N*9/10; i++ { + if i%100 == 0 { + //println("TestDNSThreadLimit:", i) + } + <-c + } + + // If we're still here, it worked. +}