66 "sort"
77 "sync"
88 "testing"
9+ "time"
910
1011 "github.com/miekg/dns"
1112 "github.com/stretchr/testify/assert"
@@ -196,6 +197,7 @@ var findXByFqdnTestCases = []struct {
196197 primaryNs string
197198 nameservers []string
198199 expectedError string
200+ timeout time.Duration
199201}{
200202 {
201203 desc : "domain is a CNAME" ,
@@ -238,6 +240,7 @@ var findXByFqdnTestCases = []struct {
238240 zone : "google.com." ,
239241 primaryNs : "ns1.google.com." ,
240242 nameservers : []string {":7053" , ":8053" , "8.8.8.8:53" },
243+ timeout : 500 * time .Millisecond ,
241244 },
242245 {
243246 desc : "only non-existent nameservers" ,
@@ -248,6 +251,7 @@ var findXByFqdnTestCases = []struct {
248251 // There a fault is marked as "connectex", not "connect", see
249252 // https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/net/fd_windows.go;l=112
250253 expectedError : "could not find the start of authority for 'mail.google.com.':" ,
254+ timeout : 500 * time .Millisecond ,
251255 },
252256 {
253257 desc : "no nameservers" ,
@@ -278,6 +282,11 @@ func TestFindZoneByFqdnCustom(t *testing.T) {
278282func TestFindPrimaryNsByFqdnCustom (t * testing.T ) {
279283 for _ , test := range findXByFqdnTestCases {
280284 t .Run (test .desc , func (t * testing.T ) {
285+ origTimeout := dnsTimeout
286+ if test .timeout > 0 {
287+ dnsTimeout = test .timeout
288+ }
289+
281290 ClearFqdnCache ()
282291
283292 ns , err := FindPrimaryNsByFqdnCustom (test .fqdn , test .nameservers )
@@ -288,6 +297,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
288297 require .NoError (t , err )
289298 assert .Equal (t , test .primaryNs , ns )
290299 }
300+
301+ dnsTimeout = origTimeout
291302 })
292303 }
293304}
0 commit comments