Skip to content

Commit

Permalink
Reduce timeout for non-existent server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Aug 4, 2023
1 parent eb34a5b commit 840b86c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion challenge/dns01/nameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"sync"
"testing"
"time"

"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -195,6 +196,7 @@ var findXByFqdnTestCases = []struct {
primaryNs string
nameservers []string
expectedError string // regular expression
timeout time.Duration
}{
{
desc: "domain is a CNAME",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -287,6 +296,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, test.primaryNs, ns)
}

dnsTimeout = origTimeout
})
}
}
Expand Down

0 comments on commit 840b86c

Please sign in to comment.