mirror of
https://github.com/golang/go
synced 2024-09-18 15:32:18 +00:00
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 <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
a27b78141b
commit
4aa7b14268
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue