Skip to content

Commit

Permalink
net/http: detect Comcast et al DNS and auto-skip DNS tests
Browse files Browse the repository at this point in the history
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
vcabbage authored and bradfitz committed Feb 1, 2017
1 parent a27b781 commit 4aa7b14
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4aa7b14

Please sign in to comment.