summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2014-10-28 16:20:49 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2014-10-28 16:20:49 +0900
commit6af6b849bdf5fd87089487dfa01e1f03b2986d74 (patch)
tree4bb123e6761b16544c51d1b84978fc8cd306133c /src/net
parent46dbd00aa2b74205e1d23c41e0df0d3b4c6b0104 (diff)
downloadgo-6af6b849bdf5fd87089487dfa01e1f03b2986d74.tar.gz
net: add test for lookupIPDeadline
Just to confirm the fix, by typing the follwing: go test -run=TestLookupIPDeadline -dnsflood or go test -run=TestLookupIPDeadline -dnsflood -tags netgo Update issue 8602 LGTM=iant R=iant CC=golang-codereviews https://codereview.appspot.com/166740043
Diffstat (limited to 'src/net')
-rw-r--r--src/net/z_last_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/net/z_last_test.go b/src/net/z_last_test.go
index 4f6a54a56..716c103db 100644
--- a/src/net/z_last_test.go
+++ b/src/net/z_last_test.go
@@ -8,6 +8,7 @@ import (
"flag"
"fmt"
"testing"
+ "time"
)
var testDNSFlood = flag.Bool("dnsflood", false, "whether to test dns query flooding")
@@ -35,3 +36,64 @@ func TestDNSThreadLimit(t *testing.T) {
// 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)
+}