Skip to content

Commit 76c0174

Browse files
TMHSDigitalclaude
andcommitted
test(dns): guard the probed name in TestProbeDenial (#234)
The test recorded the queried name in the DNS server's handler goroutine and read it from the test goroutine without synchronization, which the race detector in CI's Linux legs flagged. Guard it with a mutex. Verified: go test -race -count=3 ./internal/dns ./internal/dnsserver. Refs #234 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ddb10c1 commit 76c0174

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎internal/dns/nsec_test.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dns
33
import (
44
"context"
55
"strings"
6+
"sync"
67
"testing"
78
"time"
89

@@ -23,9 +24,14 @@ func TestProbeDenial(t *testing.T) {
2324
{"", dnstest.NXDomain, DenialNone},
2425
{"nsec", dnstest.Reply{}, DenialNSEC}, // NODATA proves absence too
2526
} {
26-
var asked string
27+
var (
28+
mu sync.Mutex
29+
asked string // written by the server's handler goroutine
30+
)
2731
srv := dnstest.Start(t, func(q dnstest.Query) dnstest.Reply {
32+
mu.Lock()
2833
asked = q.Name
34+
mu.Unlock()
2935
r := c.rcode
3036
r.Denial = c.denial
3137
return r
@@ -37,6 +43,8 @@ func TestProbeDenial(t *testing.T) {
3743
if got != c.want {
3844
t.Errorf("%q: denial = %q, want %q", c.denial, got, c.want)
3945
}
46+
mu.Lock()
47+
defer mu.Unlock()
4048
if !strings.HasSuffix(asked, ".example.test") || strings.Count(asked, ".") != 2 {
4149
t.Errorf("%q: probed %q, want a random label under example.test", c.denial, asked)
4250
}

0 commit comments

Comments
 (0)