wgengine/tsdns: skip test that requires local IPv6 when IPv6 unavailable

Fixes #1292

Cherry picked from b923ea76b1

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: Christine Dodrill <xe@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-02-16 10:20:24 -08:00 committed by Christine Dodrill
parent 7438aebad7
commit 5445a5c7b7
2 changed files with 26 additions and 7 deletions

View File

@ -5,6 +5,8 @@
package tsdns
import (
"testing"
"github.com/miekg/dns"
"inet.af/netaddr"
)
@ -71,7 +73,7 @@ func resolveToNXDOMAIN(w dns.ResponseWriter, req *dns.Msg) {
w.WriteMsg(m)
}
func serveDNS(addr string) (*dns.Server, chan error) {
func serveDNS(tb testing.TB, addr string) (*dns.Server, chan error) {
server := &dns.Server{Addr: addr, Net: "udp"}
waitch := make(chan struct{})
@ -79,7 +81,11 @@ func serveDNS(addr string) (*dns.Server, chan error) {
errch := make(chan error, 1)
go func() {
errch <- server.ListenAndServe()
err := server.ListenAndServe()
if err != nil {
tb.Logf("ListenAndServe(%q): %v", addr, err)
}
errch <- err
close(errch)
}()

View File

@ -274,15 +274,28 @@ func TestResolveReverse(t *testing.T) {
}
}
func ipv6Works() bool {
c, err := net.Listen("tcp", "[::1]:0")
if err != nil {
return false
}
c.Close()
return true
}
func TestDelegate(t *testing.T) {
rc := tstest.NewResourceCheck()
defer rc.Assert(t)
if !ipv6Works() {
t.Skip("skipping test that requires localhost IPv6")
}
dnsHandleFunc("test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
dnsHandleFunc("nxdomain.site.", resolveToNXDOMAIN)
v4server, v4errch := serveDNS("127.0.0.1:0")
v6server, v6errch := serveDNS("[::1]:0")
v4server, v4errch := serveDNS(t, "127.0.0.1:0")
v6server, v6errch := serveDNS(t, "[::1]:0")
defer func() {
if err := <-v4errch; err != nil {
@ -372,7 +385,7 @@ func TestDelegate(t *testing.T) {
func TestDelegateCollision(t *testing.T) {
dnsHandleFunc("test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
server, errch := serveDNS("127.0.0.1:0")
server, errch := serveDNS(t, "127.0.0.1:0")
defer func() {
if err := <-errch; err != nil {
t.Errorf("server error: %v", err)
@ -474,7 +487,7 @@ func TestConcurrentSetMap(t *testing.T) {
func TestConcurrentSetUpstreams(t *testing.T) {
dnsHandleFunc("test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
server, errch := serveDNS("127.0.0.1:0")
server, errch := serveDNS(t, "127.0.0.1:0")
defer func() {
if err := <-errch; err != nil {
t.Errorf("server error: %v", err)
@ -753,7 +766,7 @@ func TestTrimRDNSBonjourPrefix(t *testing.T) {
func BenchmarkFull(b *testing.B) {
dnsHandleFunc("test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."))
server, errch := serveDNS("127.0.0.1:0")
server, errch := serveDNS(b, "127.0.0.1:0")
defer func() {
if err := <-errch; err != nil {
b.Errorf("server error: %v", err)