From dd946ec5488823527bd1b2f16110d719d744bb6e Mon Sep 17 00:00:00 2001 From: James Sumners Date: Fri, 4 Aug 2023 13:43:25 -0400 Subject: [PATCH] Reduce timeout for non-existent server tests --- challenge/dns01/nameserver_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/challenge/dns01/nameserver_test.go b/challenge/dns01/nameserver_test.go index 895c7d6aa3..191dc5f630 100644 --- a/challenge/dns01/nameserver_test.go +++ b/challenge/dns01/nameserver_test.go @@ -5,6 +5,7 @@ import ( "sort" "sync" "testing" + "time" "github.com/miekg/dns" "github.com/stretchr/testify/assert" @@ -195,6 +196,7 @@ var findXByFqdnTestCases = []struct { primaryNs string nameservers []string expectedError string // regular expression + timeout time.Duration }{ { desc: "domain is a CNAME", @@ -237,6 +239,7 @@ var findXByFqdnTestCases = []struct { zone: "google.com.", primaryNs: "ns1.google.com.", nameservers: []string{":7053", ":8053", "8.8.8.8:53"}, + timeout: 500 * time.Millisecond, }, { desc: "only non-existent nameservers", @@ -246,7 +249,8 @@ var findXByFqdnTestCases = []struct { // NOTE: On Windows, net.DialContext finds a way down to the ContectEx syscall. // There a fault is marked as "connectex", not "connect", see // https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/net/fd_windows.go;l=112 - expectedError: `^could not find the start of authority for mail\.google\.com.: dial tcp :9053: connect(ex)?:`, + expectedError: `^could not find the start of authority for mail\.google\.com.: dial tcp :9053:.+`, + timeout: 500 * time.Millisecond, }, { desc: "no nameservers", @@ -277,6 +281,11 @@ func TestFindZoneByFqdnCustom(t *testing.T) { func TestFindPrimaryNsByFqdnCustom(t *testing.T) { for _, test := range findXByFqdnTestCases { t.Run(test.desc, func(t *testing.T) { + origTimeout := dnsTimeout + if test.timeout > 0 { + dnsTimeout = test.timeout + } + ClearFqdnCache() ns, err := FindPrimaryNsByFqdnCustom(test.fqdn, test.nameservers) @@ -287,6 +296,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) { require.NoError(t, err) assert.Equal(t, test.primaryNs, ns) } + + dnsTimeout = origTimeout }) } }