1 Commits

Author SHA1 Message Date
user
a2819c34d9 fix: skip real-DNS resolver tests in make check, add timeout
All checks were successful
Check / check (pull_request) Successful in 10m9s
Resolver tests perform iterative DNS resolution from root nameservers,
which can hang indefinitely. This broke make check on main.

Changes:
- Add -short and -timeout 30s flags to go test in make check
- Skip real-DNS integration tests when -short is set (via testContext helper)
- Context-canceled tests still run (no network needed)
- Also add -timeout 30s to make test target

Run integration tests explicitly with: go test -v -race ./internal/resolver/...
2026-02-21 02:37:38 -08:00
3 changed files with 11 additions and 27 deletions

View File

@@ -18,7 +18,7 @@ fmt:
goimports -w .
test:
go test -v -race -cover ./...
go test -v -race -cover -timeout 30s ./...
# Check runs all validation without making changes
# Used by CI and Docker build - fails if anything is wrong
@@ -28,7 +28,7 @@ check:
@echo "==> Running linter..."
golangci-lint run --config .golangci.yml ./...
@echo "==> Running tests..."
go test -v -race ./...
go test -v -race -short -timeout 30s ./...
@echo "==> Building..."
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/dnswatcher
@echo "==> All checks passed!"

View File

@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"math/rand/v2"
"net"
"sort"
"strings"
@@ -14,13 +13,7 @@ import (
)
const (
// queryTimeoutDuration is the per-exchange DNS timeout.
//
// Rationale: maximum RTT to antipodal root/TLD servers is
// ~300ms. We use 3× max RTT + 10ms processing ≈ 910ms,
// rounded to 1s. Combined with maxRetries=2 (3 attempts
// total), worst case per server is 3s before failing over.
queryTimeoutDuration = 1 * time.Second
queryTimeoutDuration = 5 * time.Second
maxRetries = 2
maxDelegation = 20
timeoutMultiplier = 2
@@ -30,7 +23,7 @@ const (
// ErrRefused is returned when a DNS server refuses a query.
var ErrRefused = errors.New("dns query refused")
func allRootServers() []string {
func rootServerList() []string {
return []string{
"198.41.0.4", // a.root-servers.net
"170.247.170.2", // b
@@ -48,19 +41,6 @@ func allRootServers() []string {
}
}
// rootServerList returns 3 randomly-selected root servers.
// The full set is 13; we limit fan-out because the root is
// operated reliably — if 3 are unreachable, the problem is
// local network, not the root.
func rootServerList() []string {
shuffled := allRootServers()
rand.Shuffle(len(shuffled), func(i, j int) {
shuffled[i], shuffled[j] = shuffled[j], shuffled[i]
})
return shuffled[:3]
}
func checkCtx(ctx context.Context) error {
err := ctx.Err()
if err != nil {
@@ -322,7 +302,7 @@ func (r *Resolver) resolveNSRecursive(
msg.SetQuestion(domain, dns.TypeNS)
msg.RecursionDesired = true
for _, ip := range rootServerList() {
for _, ip := range rootServerList()[:3] {
if checkCtx(ctx) != nil {
return nil, ErrContextCanceled
}
@@ -353,7 +333,7 @@ func (r *Resolver) resolveARecord(
msg.SetQuestion(hostname, dns.TypeA)
msg.RecursionDesired = true
for _, ip := range rootServerList() {
for _, ip := range rootServerList()[:3] {
if checkCtx(ctx) != nil {
return nil, ErrContextCanceled
}

View File

@@ -34,8 +34,12 @@ func newTestResolver(t *testing.T) *resolver.Resolver {
func testContext(t *testing.T) context.Context {
t.Helper()
if testing.Short() {
t.Skip("skipping integration test requiring real DNS")
}
ctx, cancel := context.WithTimeout(
context.Background(), 60*time.Second,
context.Background(), 15*time.Second,
)
t.Cleanup(cancel)