From d84fb1e5ea8f6db2dae287b2a09b91ba15e6fee6 Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Tue, 7 Jul 2026 01:04:25 -0700 Subject: [PATCH] test(prune): don't enforce wall-clock budget under -race (#4624) TestPruneLargeFixture's <5s budget is invalid under the race detector (~20s vs ~1.2s). The Main integration cmd/bd shard runs with -race; gate the timing assertion on a build-tag raceEnabled flag so only non-race builds enforce it. Correctness assertions still run under -race. --- cmd/bd/prune_bench_test.go | 8 ++++++-- cmd/bd/race_detector_off_test.go | 6 ++++++ cmd/bd/race_detector_on_test.go | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 cmd/bd/race_detector_off_test.go create mode 100644 cmd/bd/race_detector_on_test.go diff --git a/cmd/bd/prune_bench_test.go b/cmd/bd/prune_bench_test.go index de51fd788..890d33860 100644 --- a/cmd/bd/prune_bench_test.go +++ b/cmd/bd/prune_bench_test.go @@ -97,8 +97,12 @@ func TestPruneLargeFixture(t *testing.T) { t.Fatalf("buildReferencedSet error: %v", err) } - // Performance assertion (NFR-02). - if elapsed > maxDurationSeconds*time.Second { + // Performance assertion (NFR-02). The race detector adds multi-x overhead + // that invalidates a wall-clock budget (buildReferencedSet measures ~4x + // slower under -race), so only enforce the bound in non-race builds. The + // correctness assertions below still run under -race, which is where the + // large-fixture pass earns its keep as a data-race check. + if !raceEnabled && elapsed > maxDurationSeconds*time.Second { t.Errorf("buildReferencedSet took %v; must complete in <%ds on 10K-bead fixture", elapsed, maxDurationSeconds) } diff --git a/cmd/bd/race_detector_off_test.go b/cmd/bd/race_detector_off_test.go new file mode 100644 index 000000000..497fdd3b1 --- /dev/null +++ b/cmd/bd/race_detector_off_test.go @@ -0,0 +1,6 @@ +//go:build !race + +package main + +// raceEnabled is false in non-race builds; see race_detector_on_test.go. +const raceEnabled = false diff --git a/cmd/bd/race_detector_on_test.go b/cmd/bd/race_detector_on_test.go new file mode 100644 index 000000000..a0e1930eb --- /dev/null +++ b/cmd/bd/race_detector_on_test.go @@ -0,0 +1,9 @@ +//go:build race + +package main + +// raceEnabled reports whether the test binary was built with the race +// detector (-race). Wall-clock performance budgets are unreliable under +// race instrumentation (it adds multi-x overhead), so timing-sensitive +// benches consult this flag before enforcing a duration bound. +const raceEnabled = true