From: Kale Blankenship Date: Sun, 18 Dec 2016 04:40:29 +0000 (-0800) Subject: net/http: detect Comcast et al DNS and auto-skip DNS tests X-Git-Tag: go1.9beta1~1800 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4aa7b142681dba2a1d76e59ecb5dc6923a192eb0;p=gostls13.git net/http: detect Comcast et al DNS and auto-skip DNS tests Adds helper function to auto-skip tests when DNS returns a successful response for a domain known not to exist. The error from `net.LookupHost` is intentionally ignored because the DNS tests will fail anyway if there are issues unrelated to NXDOMAIN responses. Fixes #17884 Change-Id: I729391bd702218507561818668f791331295299e Reviewed-on: https://go-review.googlesource.com/34516 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index a58b1839cc..e3de3eb91b 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -3426,16 +3426,26 @@ func testTransportEventTrace(t *testing.T, h2 bool, noHooks bool) { } } -func TestTransportEventTraceRealDNS(t *testing.T) { - if testing.Short() && testenv.Builder() == "" { - // Skip this test in short mode (the default for - // all.bash), in case the user is using a shady/ISP - // DNS server hijacking queries. - // See issues 16732, 16716. - // Our builders use 8.8.8.8, though, which correctly - // returns NXDOMAIN, so still run this test there. - t.Skip("skipping in short mode") +var ( + isDNSHijackedOnce sync.Once + isDNSHijacked bool +) + +func skipIfDNSHijacked(t *testing.T) { + // Skip this test if the user is using a shady/ISP + // DNS server hijacking queries. + // See issues 16732, 16716. + isDNSHijackedOnce.Do(func() { + addrs, _ := net.LookupHost("dns-should-not-resolve.golang.") + isDNSHijacked = len(addrs) != 0 + }) + if isDNSHijacked { + t.Skip("skipping; test requires non-hijacking DNS server") } +} + +func TestTransportEventTraceRealDNS(t *testing.T) { + skipIfDNSHijacked(t) defer afterTest(t) tr := &Transport{} defer tr.CloseIdleConnections()