ReviewOS

also looking at this

zig-utils/zig-test-framework

fix: enforce bounded parallel test execution

#21
Merged glennmichael123 wants to merge codex/issue-15-bounded-parallel into main
3 files +478 -176

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

README.mdmodified+19-0
Changes to README.md
@@ -146,6 +146,25 @@ The accepted top-level sections are `test`, `parallel`, `reporter`, `snapshot`,
146146`watch`, `memory`, `ui`, and `coverage`. Options retain the same execution-mode
147147limitations as their CLI equivalents; unsupported combinations fail explicitly.
148148
149### Parallel execution semantics
150
151Programmatic runners can enable bounded execution with `RunnerOptions.parallel`
152and set `n_jobs`. A configured value is the exact maximum number of active test
153workers; omitting it uses the host's logical CPU count, with a one-worker
154fallback when detection is unavailable.
155
156Suites and nested suites are visited in declaration order. `beforeAll` and
157`afterAll` run once on the coordinating thread around that suite and its nested
158suites. Direct tests within a suite may overlap. Their inherited `beforeEach`
159and `afterEach` hooks run on the same worker as the test, so per-test hook order
160is preserved but hooks from different tests may overlap. Hook state and the
161allocator passed to tests must therefore be thread-safe.
162
163Reporter callbacks never run concurrently: test results are emitted in
164declaration order after each parallel batch, making output and final totals
165deterministic. A parallel batch is already scheduled as a unit, so `bail` cannot
166cancel tests that have started.
167
149168### Programmatic Mode
150169
151170For more control, you can manually register tests: