Skip to content

Commit fb02743

Browse files
committed
Reduce timeout for non-existent server tests
1 parent 158fbda commit fb02743

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

challenge/dns01/nameserver_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"sort"
66
"sync"
77
"testing"
8+
"time"
89

910
"github.com/miekg/dns"
1011
"github.com/stretchr/testify/assert"
@@ -195,6 +196,7 @@ var findXByFqdnTestCases = []struct {
195196
primaryNs string
196197
nameservers []string
197198
expectedError string // regular expression
199+
timeout time.Duration
198200
}{
199201
{
200202
desc: "domain is a CNAME",
@@ -237,6 +239,7 @@ var findXByFqdnTestCases = []struct {
237239
zone: "google.com.",
238240
primaryNs: "ns1.google.com.",
239241
nameservers: []string{":7053", ":8053", "8.8.8.8:53"},
242+
timeout: 500 * time.Millisecond,
240243
},
241244
{
242245
desc: "only non-existent nameservers",
@@ -246,7 +249,8 @@ var findXByFqdnTestCases = []struct {
246249
// NOTE: On Windows, net.DialContext finds a way down to the ContectEx syscall.
247250
// There a fault is marked as "connectex", not "connect", see
248251
// https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/net/fd_windows.go;l=112
249-
expectedError: `^could not find the start of authority for mail\.google\.com.: dial tcp :9053: connect(ex)?:`,
252+
expectedError: `^could not find the start of authority for mail\.google\.com.: dial tcp :9053:.+`,
253+
timeout: 500 * time.Millisecond,
250254
},
251255
{
252256
desc: "no nameservers",
@@ -277,6 +281,11 @@ func TestFindZoneByFqdnCustom(t *testing.T) {
277281
func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
278282
for _, test := range findXByFqdnTestCases {
279283
t.Run(test.desc, func(t *testing.T) {
284+
origTimeout := dnsTimeout
285+
if test.timeout > 0 {
286+
dnsTimeout = test.timeout
287+
}
288+
280289
ClearFqdnCache()
281290

282291
ns, err := FindPrimaryNsByFqdnCustom(test.fqdn, test.nameservers)
@@ -287,6 +296,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
287296
require.NoError(t, err)
288297
assert.Equal(t, test.primaryNs, ns)
289298
}
299+
300+
dnsTimeout = origTimeout
290301
})
291302
}
292303
}

0 commit comments

Comments
 (0)