66 "sort"
77 "sync"
88 "testing"
9+ "time"
910
1011 "github.com/miekg/dns"
1112 "github.com/stretchr/testify/assert"
@@ -194,6 +195,7 @@ var findXByFqdnTestCases = []struct {
194195 primaryNs string
195196 nameservers []string
196197 expectedError string
198+ timeout time.Duration
197199}{
198200 {
199201 desc : "domain is a CNAME" ,
@@ -236,6 +238,7 @@ var findXByFqdnTestCases = []struct {
236238 zone : "google.com." ,
237239 primaryNs : "ns1.google.com." ,
238240 nameservers : []string {":7053" , ":8053" , "8.8.8.8:53" },
241+ timeout : 500 * time .Millisecond ,
239242 },
240243 {
241244 desc : "only non-existent nameservers" ,
@@ -246,6 +249,7 @@ var findXByFqdnTestCases = []struct {
246249 // There a fault is marked as "connectex", not "connect", see
247250 // https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/net/fd_windows.go;l=112
248251 expectedError : "could not find the start of authority for 'mail.google.com.':" ,
252+ timeout : 500 * time .Millisecond ,
249253 },
250254 {
251255 desc : "no nameservers" ,
@@ -276,6 +280,11 @@ func TestFindZoneByFqdnCustom(t *testing.T) {
276280func TestFindPrimaryNsByFqdnCustom (t * testing.T ) {
277281 for _ , test := range findXByFqdnTestCases {
278282 t .Run (test .desc , func (t * testing.T ) {
283+ origTimeout := dnsTimeout
284+ if test .timeout > 0 {
285+ dnsTimeout = test .timeout
286+ }
287+
279288 ClearFqdnCache ()
280289
281290 ns , err := FindPrimaryNsByFqdnCustom (test .fqdn , test .nameservers )
@@ -286,6 +295,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
286295 require .NoError (t , err )
287296 assert .Equal (t , test .primaryNs , ns )
288297 }
298+
299+ dnsTimeout = origTimeout
289300 })
290301 }
291302}
0 commit comments