Skip to content

Commit a456801

Browse files
committed
net: remove redundant test case for lookupIP with threadLimit
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 <[email protected]>
1 parent 1f28238 commit a456801

File tree

2 files changed

+65
-99
lines changed

2 files changed

+65
-99
lines changed

src/net/lookup_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ package net
99

1010
import (
1111
"flag"
12+
"fmt"
1213
"strings"
1314
"testing"
15+
"time"
1416
)
1517

1618
var testExternal = flag.Bool("external", true, "allow use of external networks during long test")
@@ -229,3 +231,66 @@ func TestReverseAddress(t *testing.T) {
229231
}
230232
}
231233
}
234+
235+
var testDNSFlood = flag.Bool("dnsflood", false, "whether to test dns query flooding")
236+
237+
func TestLookupIPDeadline(t *testing.T) {
238+
if !*testDNSFlood {
239+
t.Skip("test disabled; use -dnsflood to enable")
240+
}
241+
242+
const N = 5000
243+
const timeout = 3 * time.Second
244+
c := make(chan error, 2*N)
245+
for i := 0; i < N; i++ {
246+
name := fmt.Sprintf("%d.net-test.golang.org", i)
247+
go func() {
248+
_, err := lookupIPDeadline(name, time.Now().Add(timeout/2))
249+
c <- err
250+
}()
251+
go func() {
252+
_, err := lookupIPDeadline(name, time.Now().Add(timeout))
253+
c <- err
254+
}()
255+
}
256+
qstats := struct {
257+
succeeded, failed int
258+
timeout, temporary, other int
259+
unknown int
260+
}{}
261+
deadline := time.After(timeout + time.Second)
262+
for i := 0; i < 2*N; i++ {
263+
select {
264+
case <-deadline:
265+
t.Fatal("deadline exceeded")
266+
case err := <-c:
267+
switch err := err.(type) {
268+
case nil:
269+
qstats.succeeded++
270+
case Error:
271+
qstats.failed++
272+
if err.Timeout() {
273+
qstats.timeout++
274+
}
275+
if err.Temporary() {
276+
qstats.temporary++
277+
}
278+
if !err.Timeout() && !err.Temporary() {
279+
qstats.other++
280+
}
281+
default:
282+
qstats.failed++
283+
qstats.unknown++
284+
}
285+
}
286+
}
287+
288+
// A high volume of DNS queries for sub-domain of golang.org
289+
// would be coordinated by authoritative or recursive server,
290+
// or stub resolver which implements query-response rate
291+
// limitation, so we can expect some query successes and more
292+
// failures including timeout, temporary and other here.
293+
// As a rule, unknown must not be shown but it might possibly
294+
// happen due to issue 4856 for now.
295+
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)
296+
}

src/net/z_last_test.go

-99
This file was deleted.

0 commit comments

Comments
 (0)