]> Cypherpunks repositories - gostls13.git/commitdiff
net: remove redundant test case for lookupIP with threadLimit
authorMikio Hara <mikioh.mikioh@gmail.com>
Wed, 31 Dec 2014 06:45:46 +0000 (15:45 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Thu, 1 Jan 2015 05:20:16 +0000 (05:20 +0000)
There is no reason to have the redundant test case TestDNSThreadLimt
because TestLookupIPDeadline does cover what we need to test with
-dnsflood flag and more.

Also this CL moves TestLookupIPDeadline into lookup_test.go to avoid
abusing to control the order of test case execution by using file name.

Change-Id: Ib417d7d3411c59d9352c03c996704d584368dc62
Reviewed-on: https://go-review.googlesource.com/2204
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/lookup_test.go
src/net/z_last_test.go [deleted file]

index 057e1322b998739cbba67244e5bf4f531a9d8559..430adfd4763060547181fb748726bf41769ed9d7 100644 (file)
@@ -9,8 +9,10 @@ package net
 
 import (
        "flag"
+       "fmt"
        "strings"
        "testing"
+       "time"
 )
 
 var testExternal = flag.Bool("external", true, "allow use of external networks during long test")
@@ -229,3 +231,66 @@ func TestReverseAddress(t *testing.T) {
                }
        }
 }
+
+var testDNSFlood = flag.Bool("dnsflood", false, "whether to test dns query flooding")
+
+func TestLookupIPDeadline(t *testing.T) {
+       if !*testDNSFlood {
+               t.Skip("test disabled; use -dnsflood to enable")
+       }
+
+       const N = 5000
+       const timeout = 3 * time.Second
+       c := make(chan error, 2*N)
+       for i := 0; i < N; i++ {
+               name := fmt.Sprintf("%d.net-test.golang.org", i)
+               go func() {
+                       _, err := lookupIPDeadline(name, time.Now().Add(timeout/2))
+                       c <- err
+               }()
+               go func() {
+                       _, err := lookupIPDeadline(name, time.Now().Add(timeout))
+                       c <- err
+               }()
+       }
+       qstats := struct {
+               succeeded, failed         int
+               timeout, temporary, other int
+               unknown                   int
+       }{}
+       deadline := time.After(timeout + time.Second)
+       for i := 0; i < 2*N; i++ {
+               select {
+               case <-deadline:
+                       t.Fatal("deadline exceeded")
+               case err := <-c:
+                       switch err := err.(type) {
+                       case nil:
+                               qstats.succeeded++
+                       case Error:
+                               qstats.failed++
+                               if err.Timeout() {
+                                       qstats.timeout++
+                               }
+                               if err.Temporary() {
+                                       qstats.temporary++
+                               }
+                               if !err.Timeout() && !err.Temporary() {
+                                       qstats.other++
+                               }
+                       default:
+                               qstats.failed++
+                               qstats.unknown++
+                       }
+               }
+       }
+
+       // A high volume of DNS queries for sub-domain of golang.org
+       // would be coordinated by authoritative or recursive server,
+       // or stub resolver which implements query-response rate
+       // limitation, so we can expect some query successes and more
+       // failures including timeout, temporary and other here.
+       // As a rule, unknown must not be shown but it might possibly
+       // happen due to issue 4856 for now.
+       t.Logf("%v succeeded, %v failed (%v timeout, %v temporary, %v other, %v unknown)", qstats.succeeded, qstats.failed, qstats.timeout, qstats.temporary, qstats.other, qstats.unknown)
+}
diff --git a/src/net/z_last_test.go b/src/net/z_last_test.go
deleted file mode 100644 (file)
index 716c103..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-// 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 (
-       "flag"
-       "fmt"
-       "testing"
-       "time"
-)
-
-var testDNSFlood = flag.Bool("dnsflood", false, "whether to test dns query flooding")
-
-func TestDNSThreadLimit(t *testing.T) {
-       if !*testDNSFlood {
-               t.Skip("test disabled; use -dnsflood to enable")
-       }
-
-       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 TestLookupIPDeadline(t *testing.T) {
-       if !*testDNSFlood {
-               t.Skip("test disabled; use -dnsflood to enable")
-       }
-
-       const N = 5000
-       const timeout = 3 * time.Second
-       c := make(chan error, 2*N)
-       for i := 0; i < N; i++ {
-               name := fmt.Sprintf("%d.net-test.golang.org", i)
-               go func() {
-                       _, err := lookupIPDeadline(name, time.Now().Add(timeout/2))
-                       c <- err
-               }()
-               go func() {
-                       _, err := lookupIPDeadline(name, time.Now().Add(timeout))
-                       c <- err
-               }()
-       }
-       qstats := struct {
-               succeeded, failed         int
-               timeout, temporary, other int
-               unknown                   int
-       }{}
-       deadline := time.After(timeout + time.Second)
-       for i := 0; i < 2*N; i++ {
-               select {
-               case <-deadline:
-                       t.Fatal("deadline exceeded")
-               case err := <-c:
-                       switch err := err.(type) {
-                       case nil:
-                               qstats.succeeded++
-                       case Error:
-                               qstats.failed++
-                               if err.Timeout() {
-                                       qstats.timeout++
-                               }
-                               if err.Temporary() {
-                                       qstats.temporary++
-                               }
-                               if !err.Timeout() && !err.Temporary() {
-                                       qstats.other++
-                               }
-                       default:
-                               qstats.failed++
-                               qstats.unknown++
-                       }
-               }
-       }
-
-       // A high volume of DNS queries for sub-domain of golang.org
-       // would be coordinated by authoritative or recursive server,
-       // or stub resolver which implements query-response rate
-       // limitation, so we can expect some query successes and more
-       // failures including timeout, temporary and other here.
-       // As a rule, unknown must not be shown but it might possibly
-       // happen due to issue 4856 for now.
-       t.Logf("%v succeeded, %v failed (%v timeout, %v temporary, %v other, %v unknown)", qstats.succeeded, qstats.failed, qstats.timeout, qstats.temporary, qstats.other, qstats.unknown)
-}