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 13 additions and 19 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

@@ -13,7 +13,7 @@ import (
)
const (
queryTimeoutDuration = 700 * time.Millisecond
queryTimeoutDuration = 5 * time.Second
maxRetries = 2
maxDelegation = 20
timeoutMultiplier = 2
@@ -291,17 +291,8 @@ func (r *Resolver) resolveNSIPs(
return ips
}
// publicResolvers returns well-known public recursive DNS resolvers.
func publicResolvers() []string {
return []string{
"1.1.1.1", // Cloudflare
"8.8.8.8", // Google
"9.9.9.9", // Quad9
}
}
// resolveNSRecursive queries for NS records using a public
// recursive resolver as a fallback for intercepted environments.
// resolveNSRecursive queries for NS records using recursive
// resolution as a fallback for intercepted environments.
func (r *Resolver) resolveNSRecursive(
ctx context.Context,
domain string,
@@ -311,7 +302,7 @@ func (r *Resolver) resolveNSRecursive(
msg.SetQuestion(domain, dns.TypeNS)
msg.RecursionDesired = true
for _, ip := range publicResolvers() {
for _, ip := range rootServerList()[:3] {
if checkCtx(ctx) != nil {
return nil, ErrContextCanceled
}
@@ -332,8 +323,7 @@ func (r *Resolver) resolveNSRecursive(
return nil, ErrNoNameservers
}
// resolveARecord resolves a hostname to IPv4 addresses using
// public recursive resolvers.
// resolveARecord resolves a hostname to IPv4 addresses.
func (r *Resolver) resolveARecord(
ctx context.Context,
hostname string,
@@ -343,7 +333,7 @@ func (r *Resolver) resolveARecord(
msg.SetQuestion(hostname, dns.TypeA)
msg.RecursionDesired = true
for _, ip := range publicResolvers() {
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)