Skip to content

Commit 5c582b9

Browse files
committed
Give end-to-end tests load-tolerant DNS timeouts (#289)
Several end-to-end tests asked an in-process DNS server with short, single-attempt timeouts, so a busy machine turned a late answer into a failure. Runs that expect real answers now use the lab timing (5 s, 3 attempts) through a localArgs helper; zones with records that never answer use 2 s and 2 attempts; single-attempt 2 s timeouts against servers that answer at once are raised to 10 s; the lab 3 "unreliable" case keeps one attempt; and the interrupted run in TestE2EResume uses one worker. What the tests assert is unchanged. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com> Refs #289
1 parent 04ffe4a commit 5c582b9

8 files changed

Lines changed: 60 additions & 34 deletions

File tree

‎internal/cli/axfr_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func runAXFR(t *testing.T, srv *dnstest.Server, args ...string) (int, string) {
5454
if err != nil {
5555
t.Fatal(err)
5656
}
57-
return runCLIMergedWith(t, runArgs{axfrPort: port, args: args})
57+
return runCLIMergedWith(t, runArgs{axfrPort: port, args: localArgs(args...)})
5858
}
5959

6060
// TestE2EZoneTransfer covers #85: a name server that allows AXFR gives

‎internal/cli/ct_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestE2ECertificateTransparency(t *testing.T) {
4545
stats := filepath.Join(t.TempDir(), "run.json")
4646
scan := func(base string) (int, string, output.Summary) {
4747
code, out := runCLIWith(t, runArgs{sourceURLs: map[string]string{"ct": base + "/"},
48-
args: []string{"-ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl, "example.com"}})
48+
args: append(localArgs("-ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl), "example.com")})
4949
var s output.Summary
5050
if data, err := os.ReadFile(stats); err == nil {
5151
_ = json.Unmarshal(data, &s)
@@ -113,7 +113,7 @@ func TestE2EPassiveSources(t *testing.T) {
113113
}
114114

115115
code, out := runCLIWith(t, runArgs{sourceURLs: map[string]string{"ct": ctUp.URL + "/", "wayback": wayback.URL},
116-
args: []string{"-ct", "-sources", "wayback", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl, "example.com"}})
116+
args: append(localArgs("-ct", "-sources", "wayback", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl), "example.com")})
117117
if code != 0 || !strings.Contains(out, "legacy-billing.example.com") || !strings.Contains(out, "old-shop.example.com") {
118118
t.Fatalf("exit %d, results %q: want the CT and the Wayback name", code, out)
119119
}
@@ -133,7 +133,7 @@ func TestE2EPassiveSources(t *testing.T) {
133133
"old-shop.example.com": "wayback",
134134
}
135135
sourceArgs := runArgs{sourceURLs: map[string]string{"ct": ctUp.URL + "/", "wayback": wayback.URL}}
136-
scanArgs := []string{"-sources", "ct,wayback", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-w", wl, "example.com"}
136+
scanArgs := append(localArgs("-sources", "ct,wayback", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-w", wl), "example.com")
137137
sourceArgs.args = append([]string{"-format", "jsonl"}, scanArgs...)
138138
code, out = runCLIWith(t, sourceArgs)
139139
got := map[string]string{}
@@ -168,7 +168,7 @@ func TestE2EPassiveSources(t *testing.T) {
168168
}
169169

170170
code, out = runCLIWith(t, runArgs{sourceURLs: map[string]string{"ct": ctUp.URL + "/", "wayback": down.URL},
171-
args: []string{"-sources", "wayback,ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl, "example.com"}})
171+
args: append(localArgs("-sources", "wayback,ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-stats", stats, "-w", wl), "example.com")})
172172
if code != 0 || !strings.Contains(out, "legacy-billing.example.com") || strings.Contains(out, "old-shop") {
173173
t.Errorf("wayback down: exit %d, results %q; want the CT name only", code, out)
174174
}

‎internal/cli/dryrun_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func TestDryRunPreflight(t *testing.T) {
8888
defer srv.Close()
8989
// The server answers at once; the timeout only has to cover the
9090
// stub resolver's own SERVFAIL retry, even on a loaded machine
91-
// (#235).
92-
code, plans := dryRunPlans(t, "-dns-server", srv.Addr, "-timeout", "2000", "-attempts", "1",
91+
// (#235, #289).
92+
code, plans := dryRunPlans(t, "-dns-server", srv.Addr, "-timeout", "10000", "-attempts", "1",
9393
"-type", "A", "-w", wl, "example.com")
9494
if code != tc.code {
9595
t.Errorf("exit %d, want %d", code, tc.code)

‎internal/cli/e2e_test.go‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func writeFile(t *testing.T, name, content string) string {
110110
return p
111111
}
112112

113+
// localArgs puts labTimingArgs in front of args, for a run that expects real
114+
// answers from an in-process DNS server (#289).
115+
func localArgs(args ...string) []string {
116+
return append(slices.Clone(labTimingArgs), args...)
117+
}
118+
113119
const e2eWords = "www\nmail\napi\ndev\nshop\nblog\n"
114120

115121
func TestE2ESimulateJSON(t *testing.T) {
@@ -511,8 +517,8 @@ func TestE2EResolverPool(t *testing.T) {
511517
wl := writeFile(t, "wl.txt", e2eWords)
512518
list := writeFile(t, "resolvers.txt", "# pool\n"+r1+"\n"+r2+"\n")
513519
stats := filepath.Join(t.TempDir(), "run.json")
514-
code, _ := runCLI(t, "", "-dns-server", trusted, "-r", list, "-type", "A", "-progress=false",
515-
"-stats", stats, "-w", wl, "example.com")
520+
code, _ := runCLI(t, "", append(localArgs("-dns-server", trusted, "-r", list, "-type", "A", "-progress=false",
521+
"-stats", stats, "-w", wl), "example.com")...)
516522
if code != 0 {
517523
t.Fatalf("exit %d", code)
518524
}
@@ -562,7 +568,7 @@ func TestE2EDiff(t *testing.T) {
562568
t.Parallel()
563569
dir := t.TempDir()
564570
zone := writeFile(t, "now.zone", "www A 192.0.2.10\nmail A 192.0.2.20\ndev A 192.0.2.30\nextra A 192.0.2.40\nlegacy TIMEOUT\n")
565-
lab := []string{"-simulate-zone", zone, "-timeout", "200", "-progress=false"}
571+
lab := append([]string{"-simulate-zone", zone, "-progress=false"}, labSlowTimingArgs...)
566572
run := func(words string, extra ...string) (int, string) {
567573
wl := writeFile(t, "wl.txt", words)
568574
return runCLI(t, "", append(append(append([]string{}, lab...), extra...), "-w", wl, "lab.example")...)
@@ -671,8 +677,8 @@ func TestE2EPermute(t *testing.T) {
671677
})
672678
wl := writeFile(t, "wl.txt", "api\nwww\n")
673679
stats := filepath.Join(t.TempDir(), "run.json")
674-
code, out := runCLI(t, "", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-permute",
675-
"-format", "jsonl", "-stats", stats, "-w", wl, "example.com")
680+
code, out := runCLI(t, "", append(localArgs("-dns-server", srv.Addr, "-type", "A", "-progress=false", "-permute",
681+
"-format", "jsonl", "-stats", stats, "-w", wl), "example.com")...)
676682
if code != 0 {
677683
t.Fatalf("exit %d", code)
678684
}
@@ -742,8 +748,8 @@ func TestE2EInconclusive(t *testing.T) {
742748
dir := t.TempDir()
743749
incon, stats := filepath.Join(dir, "incon.txt"), filepath.Join(dir, "run.json")
744750
before := srv.QueriesFor("down.example.com", dnsmessage.TypeA)
745-
args := []string{"-dns-server", srv.Addr, "-type", "A", "-progress=false", "-no-abort",
746-
"-inconclusive", incon, "-stats", stats, "-w", wl, "example.com"}
751+
args := append(localArgs("-dns-server", srv.Addr, "-type", "A", "-progress=false", "-no-abort",
752+
"-inconclusive", incon, "-stats", stats, "-w", wl), "example.com")
747753
if retry {
748754
args = append([]string{"-retry-inconclusive"}, args...)
749755
}
@@ -800,8 +806,8 @@ func TestE2EInternalAddresses(t *testing.T) {
800806
})
801807
wl := writeFile(t, "wl.txt", "www\nintranet\nlo\nnope\n")
802808
stats := filepath.Join(t.TempDir(), "run.json")
803-
code, out := runCLI(t, "", "-dns-server", srv.Addr, "-type", "A", "-progress=false",
804-
"-format", "jsonl", "-stats", stats, "-w", wl, "example.com")
809+
code, out := runCLI(t, "", append(localArgs("-dns-server", srv.Addr, "-type", "A", "-progress=false",
810+
"-format", "jsonl", "-stats", stats, "-w", wl), "example.com")...)
805811
if code != 0 {
806812
t.Fatalf("exit %d", code)
807813
}
@@ -833,7 +839,7 @@ func TestE2EInternalAddresses(t *testing.T) {
833839
t.Errorf("report internal_addresses: %s (err %v), want 2", raw, err)
834840
}
835841

836-
_, text := runCLI(t, "", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-show-records", "-w", wl, "example.com")
842+
_, text := runCLI(t, "", append(localArgs("-dns-server", srv.Addr, "-type", "A", "-progress=false", "-show-records", "-w", wl), "example.com")...)
837843
for _, line := range strings.Split(strings.TrimSpace(text), "\n") {
838844
hasMarker := strings.Contains(line, " INTERNAL=")
839845
if strings.HasPrefix(line, "www.") == hasMarker {
@@ -866,7 +872,7 @@ func TestE2ETakeoverProviders(t *testing.T) {
866872
})
867873
wl := writeFile(t, "wl.txt", "docs\nwww\n")
868874
scan := func(extra ...string) (int, string) {
869-
args := append([]string{"-dns-server", srv.Addr, "-type", "A,CNAME", "-progress=false", "-show-records", "-w", wl}, extra...)
875+
args := append(localArgs("-dns-server", srv.Addr, "-type", "A,CNAME", "-progress=false", "-show-records", "-w", wl), extra...)
870876
return runCLI(t, "", append(args, "example.com")...)
871877
}
872878
if _, out := scan(); strings.Contains(out, "TAKEOVER?") {
@@ -921,10 +927,13 @@ func TestE2EResume(t *testing.T) {
921927
}
922928

923929
// Interrupted run: -rate 20 makes 40 names take ~2s; interrupt once
924-
// three results are out, whatever the runner's speed (#260).
930+
// three results are out, whatever the runner's speed (#260). One worker
931+
// takes its rate slot only after the previous lookup, so a stalled
932+
// process cannot run the rest in a burst before the interrupt is handled,
933+
// as many workers holding slots reserved up front could (#289).
925934
signals := make(chan os.Signal, 1)
926935
code, first := runCLIUntilLines(t, 3, func() { signals <- os.Interrupt }, runArgs{signals: signals,
927-
args: append(append([]string{}, base...), "-rate", "20", "-state", statePath, "-o", outPath, "example.com")})
936+
args: append(append([]string{}, base...), "-t", "1", "-rate", "20", "-state", statePath, "-o", outPath, "example.com")})
928937
if code != 130 {
929938
t.Fatalf("interrupted run: exit %d, want 130", code)
930939
}

‎internal/cli/lab_test.go‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ import (
1212
"github.com/TMHSDigital/subenum/internal/dns"
1313
)
1414

15-
// labTimingArgs gives lab runs a generous per-query timeout and retries. The
16-
// lab server is in-process, so the CLI's 1 s default is ample on an idle
17-
// machine but not under -race and coverage on a busy CI runner (#167).
15+
// labTimingArgs gives lab runs, and any other run against an in-process DNS
16+
// server, a generous per-query timeout and retries. The server is in-process,
17+
// so the CLI's 1 s default is ample on an idle machine but not under -race
18+
// and coverage on a busy CI runner (#167), or beside other parallel tests and
19+
// packages (#289).
1820
var labTimingArgs = []string{"-timeout", "5000", "-attempts", "3"}
1921

22+
// labSlowTimingArgs is for zones with TIMEOUT records, where each name that
23+
// never answers costs every attempt's full timeout: shorter than
24+
// labTimingArgs to keep the test quick, but still two tries of two seconds
25+
// for the names that do answer (#289).
26+
var labSlowTimingArgs = []string{"-timeout", "2000", "-attempts", "2"}
27+
2028
// TestE2ELabs runs the shipped -simulate-zone scenarios end to end (#76) and
2129
// checks the answers the Labs page gives for them.
2230
func TestE2ELabs(t *testing.T) {
@@ -96,9 +104,11 @@ func TestE2ELabVerdicts(t *testing.T) {
96104
zone, verdict string
97105
args []string
98106
}{
99-
{zone: "lab3-rate-limit.zone", verdict: "unreliable"},
100-
{zone: "lab3-rate-limit.zone", verdict: "complete", args: []string{"-rate", "30"}},
101-
{zone: "lab5-failures.zone", verdict: "degraded", args: []string{"-timeout", "200"}},
107+
// One attempt: a retry lands in a later one-second window and gets
108+
// answered, which on a slow machine turns the verdict into degraded.
109+
{zone: "lab3-rate-limit.zone", verdict: "unreliable", args: []string{"-timeout", "5000", "-attempts", "1"}},
110+
{zone: "lab3-rate-limit.zone", verdict: "complete", args: append([]string{"-rate", "30"}, labTimingArgs...)},
111+
{zone: "lab5-failures.zone", verdict: "degraded", args: labSlowTimingArgs},
102112
} {
103113
t.Run(c.zone+strings.Join(c.args, ""), func(t *testing.T) {
104114
stats := filepath.Join(t.TempDir(), "run.json")
@@ -132,8 +142,8 @@ func TestE2EMaxDuration(t *testing.T) {
132142
t.Parallel()
133143
stats := filepath.Join(t.TempDir(), "run.json")
134144
// -rate 10 with 30 words needs about 3 s; the budget is a third of that.
135-
code, out := runCLI(t, "", "-progress=false", "-w", "examples/labs/words.txt", "-t", "2", "-rate", "10",
136-
"-max-duration", "1s", "-stats", stats, "-state", filepath.Join(t.TempDir(), "state.json"), "-simulate-zone", filepath.Join("examples", "labs", "lab1-first-scan.zone"), "lab.example")
145+
code, out := runCLI(t, "", append(localArgs("-progress=false", "-w", "examples/labs/words.txt", "-t", "2", "-rate", "10",
146+
"-max-duration", "1s", "-stats", stats, "-state", filepath.Join(t.TempDir(), "state.json"), "-simulate-zone", filepath.Join("examples", "labs", "lab1-first-scan.zone")), "lab.example")...)
137147
if code != 0 {
138148
t.Fatalf("exit %d\n%s", code, out)
139149
}

‎internal/cli/resume_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ func TestE2EAbortSavesResumeState(t *testing.T) {
421421
defer srv.Close()
422422
dir := t.TempDir()
423423
state, stats := filepath.Join(dir, "state.json"), filepath.Join(dir, "run.json")
424-
code, out := runCLIMerged(t, "-progress=false", "-dns-server", srv.Addr, "-timeout", "2000", "-attempts", "1", "-type", "A",
424+
// The server answers at once, so the long timeout costs nothing (#289).
425+
code, out := runCLIMerged(t, "-progress=false", "-dns-server", srv.Addr, "-timeout", "10000", "-attempts", "1", "-type", "A",
425426
"-t", "4", "-state", state, "-stats", stats, "-w", writeFile(t, "wl.txt", words.String()), "example.com")
426427
if code != exitFailure {
427428
t.Fatalf("aborted run: exit %d, want %d\n%s", code, exitFailure, out)
@@ -543,7 +544,7 @@ func TestE2EResumeReplaysSourceNames(t *testing.T) {
543544
"sources": {"-sources=ct", resumeTarget{Domain: "example.com", Sources: map[string][]string{"ct": {"legacy"}}}},
544545
"legacy": {"-ct", resumeTarget{Domain: "example.com", CT: []string{"legacy"}, CTFetched: true}},
545546
} {
546-
args := []string{tc.flag, "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-w", wl, "example.com"}
547+
args := append(localArgs(tc.flag, "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-w", wl), "example.com")
547548
path := writeState(t, resumeState{Args: args, Targets: []resumeTarget{tc.saved}})
548549
hits.Store(0)
549550
code, out := runCLIWith(t, runArgs{sourceURLs: urls, args: []string{"-resume", path}})
@@ -709,7 +710,7 @@ func TestE2EResumeRefetchesInterruptedSource(t *testing.T) {
709710
wl := writeFile(t, "wl.txt", "www\n")
710711
path := filepath.Join(t.TempDir(), "state.json")
711712
code, out := runCLIMergedWith(t, runArgs{sourceURLs: urls, signals: signals,
712-
args: []string{"-ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-state", path, "-w", wl, "example.com"}})
713+
args: append(localArgs("-ct", "-dns-server", srv.Addr, "-type", "A", "-progress=false", "-state", path, "-w", wl), "example.com")})
713714
if code != 130 {
714715
t.Fatalf("interrupted run: exit %d, want 130\n%s", code, out)
715716
}

‎internal/dns/transport_test.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,16 @@ func TestTimedOutLookupSendsNoLateQueries(t *testing.T) {
204204
func TestDoTDiscardsClosedConnections(t *testing.T) {
205205
srv, servers := startAllTransports(t)
206206
srv.CloseStreamsAfter(1)
207-
r := NewResolver(2*time.Second, servers[TransportTLS])
207+
// Each lookup pays a TLS handshake, which a loaded machine can stretch
208+
// past a couple of seconds; the server answers at once, so a long timeout
209+
// costs nothing (#289).
210+
const timeout = 10 * time.Second
211+
r := NewResolver(timeout, servers[TransportTLS])
208212
var sent atomic.Int64
209213
ctx := WithQueryCounter(context.Background(), &sent)
210214
before := srv.Connections()
211215
for i := 0; i < 10; i++ {
212-
if _, _, err := (Lookup{Resolver: r, Timeout: 2 * time.Second, Types: []string{"A"}}).ResolveTypes(ctx, "www.example.com"); err != nil {
216+
if _, _, err := (Lookup{Resolver: r, Timeout: timeout, Types: []string{"A"}}).ResolveTypes(ctx, "www.example.com"); err != nil {
213217
t.Fatal(err)
214218
}
215219
time.Sleep(5 * time.Millisecond) // let the server's close arrive

‎pkg/subenum/subenum_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ func TestNoAbortScanSucceedsDespiteFailingLookups(t *testing.T) {
489489
Domain: "lab.example",
490490
Words: words,
491491
Resolver: srv.Addr,
492-
Timeout: 2 * time.Second,
492+
// The server answers every query at once, so a long timeout costs
493+
// nothing and keeps a loaded machine from failing the preflight (#289).
494+
Timeout: 10 * time.Second,
493495
Attempts: 1,
494496
NoAbort: true,
495497
}

0 commit comments

Comments
 (0)