From 4b72d62558739a3c5a93ef1de46db07b870ae18b Mon Sep 17 00:00:00 2001 From: nova-loop Date: Fri, 20 Nov 2026 10:01:45 +0800 Subject: [PATCH] Count dialed queries in TestCheckWildcardInconclusive (#439) The timeout case counted packets the test server received. On a loaded machine an attempt's 100 ms can expire before its packet is written, so the server saw one query although the probe was retried. Count the queries the client dials with WithQueryCounter instead. Closes #439 --- internal/dns/resolver_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/dns/resolver_test.go b/internal/dns/resolver_test.go index dcba799..25a1b53 100644 --- a/internal/dns/resolver_test.go +++ b/internal/dns/resolver_test.go @@ -125,7 +125,13 @@ func TestCheckWildcardInconclusive(t *testing.T) { t.Run(tc.name, func(t *testing.T) { srv := startTestDNS(t, map[string]testReply{"*": tc.reply}) timeout := 100 * time.Millisecond - is, fp, err := Lookup{Resolver: srv.Resolver(timeout), Timeout: timeout, Attempts: 2, Types: []string{"A"}}.CheckWildcard(context.Background(), "example.com") + // Count queries as the client dials them rather than as the + // server receives them: on a loaded machine an attempt's 100 ms + // can run out before its packet is written, so the server may + // see one query although the probe was retried (#439). + var dialed atomic.Int64 + ctx := WithQueryCounter(context.Background(), &dialed) + is, fp, err := Lookup{Resolver: srv.Resolver(timeout), Timeout: timeout, Attempts: 2, Types: []string{"A"}}.CheckWildcard(ctx, "example.com") if !errors.Is(err, ErrWildcardInconclusive) { t.Fatalf("err = %v, want ErrWildcardInconclusive", err) } @@ -135,8 +141,8 @@ func TestCheckWildcardInconclusive(t *testing.T) { // The check stops at the first inconclusive probe, after its two // attempts. Go's resolver may itself retry a SERVFAIL, so only // require that the retry happened. - if got := srv.Queries(); got < 2 { - t.Fatalf("queries = %d, want >= 2 (the probe retried)", got) + if got := dialed.Load(); got < 2 { + t.Fatalf("queries dialed = %d, want >= 2 (the probe retried)", got) } }) }