Repository navigation
Description
Summary
The Typhon.Engine.Tests suite had drifted from its original ~9 s wall-clock to 31.6 s with one confirmed flake and a 5 s variance bomb. This issue tracks a cleanup pass that:
- Retired benchmark-style tests masquerading as regressions
- Eliminated a global-static race that caused a 5 s spike in one test on ~1/3 of runs
- Optimized 36 individual heavy tests (loop counts, timeouts, timer intervals, one O(n²)→O(n) algorithmic fix)
- Built coverage-driven analysis to identify redundant test clusters
- Shipped per-fixture test-selection tooling (
scripts/test-affected.py) so iteration runs only the fixtures that exercise the edited file (~1.7 s vs 30 s)
Full report: claude/scratch/test-suite-cleanup-2026-05-04.md.
Net result (avg of 3 fresh runs each)
| Metric | Before | After | Δ |
|---|---|---|---|
| Wall-clock | 31.6 s | 28.1 s | −3.5 s (≈ 11 %) |
| CPU sum | 57.5 s | 43.4 s | −14 s (≈ 24 %) |
| Variance spike | 5 039 ms (1/3 runs) | gone (deterministic ~80 ms) | — |
| Iteration-mode (focused edit) | 30 s | 1.7 s | 18× speedup |
The wall-clock saving is smaller than the CPU saving because the suite already runs at 4-way parallelism; the heaviest gain on iteration speed is from running fewer tests, not from running them faster.
What changed
Phase 1 — Retire Report_* benchmarks
Six Report_* methods in Runtime/DagSchedulerCpuTests.cs and Runtime/DagSchedulerLatencyTests.cs marked [Explicit]. They are CPU/latency measurements over multi-second windows (busy-spin loops with Stopwatch), not regression assertions — they belong with the benchmark suite. Functional DagScheduler regression coverage stays in DagSchedulerTests.cs (15 tests, untouched).
Phase 2.2 — Defuse a 5 s variance bomb
ExceptionPathLeakTests.GetRevisionElement_WhenLockTimeout_DoesNotLeakChunkHandles showed 78 ms ↔ 5 039 ms variance (1 of 3 runs spiked). Root cause: TimeoutOptions.Current is a process-global static (src/Typhon.Engine/Data/TimeoutOptions.cs:28). Every parallel DatabaseEngine ctor writes it (DatabaseEngine.cs:495). Test SetUp overrides RevisionChainLockTimeout to 50 ms, but a parallel fixture's DBE ctor immediately reverts it to the default 5 s — exactly the spike. Marked ExceptionPathLeakTests and TransactionUnitOfWorkContextTests (same pattern) [NonParallelizable]. Spike eliminated; test now deterministic at ~80 ms.
A separate ticket should cover refactoring TimeoutOptions.Current to be per-DatabaseEngine rather than process-global — the static is a footgun for any hosted multi-engine scenario, not just tests.
Phase H — Heavy-test optimization (36 tests, 14 files)
For each of the 78 tests ≥ 100 ms (47 % of CPU-sum), reviewed for over-iteration / over-margin and reduced where coverage was preserved:
LockTest: 10 000 → 2 000 iterations (32 threads × 2 000 = 64 000 ops still ample for race detection)ReliabilityTest: 25 frames × 1 000 ops → 10 × 500TransactionChain.Stress_ConcurrentCreateDispose: 200 ms → 50 ms holdConcurrentBitmapL3 stress: 5 000 → 2 000 ops/threadWAL_ManyEntities_SurvivesReopen: 500 → 100 entities- 12 lock-timeout tests in
AccessControlSmallTests/ResourceAccessControlTests: 100 ms → 30 ms timeouts - 8 timer tests in
HighResolutionSharedTimerServiceTests:Stopwatch.Frequency / 10(100 ms tick) →/100(10 ms) — these tests verify register/dispose semantics, not interval correctness ChunkBasedSegmentBitmapL3Tests.ClearL0_MultipleGroups_BitmapConsistency:List<int>.Contains→HashSet<int>.Contains(was O(n²) on hundreds of chunks)- Dropped redundant
CreateAndLoadBigSegment(4500)test case (kept 5 000) - Various
LiveConnectTimeout,Rent_PoolExhausted,DeadlineWatchdogreductions
Aggregate: 36 tests dropped from 6 870 ms → 3 737 ms CPU.
Phase C — Coverage-driven analysis (no edits, just findings)
- Per-fixture cobertura coverage for all 233 fixtures.
- Leave-one-out analysis with "noise floor" filter (classes that drop on ≥ 4 of 14 exclusions are shared infrastructure, not real coverage targets).
- Findings (real unique line coverage when fixture excluded):
EcsHardeningTests: 44 tests → 0 unique linesEcsSpawnMvccTests: 37 tests → 0 unique linesWalIntegrationTests: 43 tests, 3.0 s CPU → 0 unique lines (kept — owns durability/replay scenarios that line coverage doesn't see)HashMap*cluster: 201 tests → 11 unique linesBlockAllocator*cluster: 147 tests → 26 unique lines
- Recommendation matrix in the full report. Trim candidates require per-test review (tracked as follow-ups, not in this issue).
Phase T — scripts/test-affected.py + scripts/build-test-affected-map.py
Default workflow during iteration is now: edit → python3 scripts/test-affected.py <files> → fixture-scoped run (typical 1–3 s). Full suite only at handoff or after cross-cutting changes.
- 366 src files mapped (median 4 fixtures/file). 214 files (58 %) resolve to ≤ 5 fixtures (clean local-edit fast path); 80 files (22 %) resolve to full suite (genuinely cross-cutting primitives like
PagedMMF,AccessControlSmall). - Builder is incremental: 0.3 s when nothing changed (parsed-JSON cache), ~5 s per touched test file. Initial build (no cache) is ~25 min.
- Two-layer cache: cobertura XML invalidated by test-file mtime; parsed-result JSON invalidated only when its XML changes. The JSON layer is what makes the no-change rebuild instant.
--forcefor full rebuild after a class-moves-between-files refactor.--only Foo Barto recover from individual failed runs.
CLAUDE.md updated with the new default workflow.
Files touched
19 modified files (test edits + CLAUDE.md), 5 new files (scripts/test-affected.py, scripts/build-test-affected-map.py, scripts/README.md, coverage/test-affected-map.json, coverage/fixtures.txt), plus coverage/per_fixture/ cache directory (gitignored — empty XML cache files don't need to ship).
Follow-ups (separate tickets)
- OlcBTree concurrent-tests diagnostic capture: per-thread
ConcurrentBag<Exception>(currentlyInterlocked.Increment(ref errors)swallows the actual exception). Lets us diagnoseAdd_ConcurrentInsertsCausingSplits_TreeConsistent/Remove_MixedInsertAndRemove_NoCorruptionflakes when they next surface. TimeoutOptions.Currentglobal static refactor: threadTimeoutOptionsreference through every read site (~30 call sites). Out of scope here; mechanical but invasive.- Phase 4 (cold-fixture warmup): 21
Runtime.*tests pay ~110 ms first-test penalty. Single shared[SetUpFixture]fix likely to recover ~2 s wall. - Coverage-driven trim: per-test attribution within the high-redundancy clusters identified above (HashMap, BlockAllocator, EcsHardening, EcsSpawnMvcc) — needs the per-test attribution that the leave-one-out analysis pointed to.
Test plan
- Full suite passes (3 fresh runs post-changes; only pre-existing OlcBTree flakes resurfaced — Phase 2.1 territory).
-
test-affected.pyend-to-end on 4+ representative cases (local edit, cross-cutting, multi-file, no-match fallback). - Incremental builder verified: 0.3 s no-change, ~5 s after touching one test file.
- Variance test goes from 5 039 ms → ~80 ms deterministic.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Solved #296 (#301)