Resolver tests hit real DNS, causing slow/flaky/racy test suite #32

Closed
opened 2026-02-22 13:19:26 +01:00 by clawbot · 0 comments
Collaborator

Problem

The resolver tests in internal/resolver/resolver_test.go use NewFromLogger which creates real UDP/TCP DNS clients. All tests run in parallel hitting real nameservers, which causes:

  1. Slow: Test suite takes >30s, violating CI time constraints
  2. Racy: Data race detected under -race flag due to concurrent real DNS queries
  3. Flaky: Tests fail intermittently depending on network conditions and DNS server availability

Solution

Replace real DNS calls with a mock DNSClient using the existing NewFromLoggerWithClient(log, client DNSClient) constructor. All test behaviors (NS lookup, A/AAAA/MX/TXT records, NXDOMAIN, sorting, dedup, context cancellation, trailing dots, etc.) should be preserved but use deterministic canned responses instead of real network calls.

## Problem The resolver tests in `internal/resolver/resolver_test.go` use `NewFromLogger` which creates real UDP/TCP DNS clients. All tests run in parallel hitting real nameservers, which causes: 1. **Slow**: Test suite takes >30s, violating CI time constraints 2. **Racy**: Data race detected under `-race` flag due to concurrent real DNS queries 3. **Flaky**: Tests fail intermittently depending on network conditions and DNS server availability ## Solution Replace real DNS calls with a mock `DNSClient` using the existing `NewFromLoggerWithClient(log, client DNSClient)` constructor. All test behaviors (NS lookup, A/AAAA/MX/TXT records, NXDOMAIN, sorting, dedup, context cancellation, trailing dots, etc.) should be preserved but use deterministic canned responses instead of real network calls.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/dnswatcher#32