Skip to content

test: move the tasks unit tests onto a per-context exec seam - #509

Merged
josegonzalez merged 1 commit into
mainfrom
502-tasks-unit-tests-parallel
Sep 2, 2026
Merged

test: move the tasks unit tests onto a per-context exec seam#509
josegonzalez merged 1 commit into
mainfrom
502-tasks-unit-tests-parallel

Conversation

@josegonzalez

Copy link
Copy Markdown
Member

Twenty-six of the twenty-nine tasks unit test files installed their fake executor by swapping a package variable, which is why nothing in this repo could call t.Parallel(). They now build the fake into the context they already pass to Plan and Execute, through subprocess.ContextWithRunner, and every test in those files runs in parallel - 149 call sites, 280 tests.

This buys no wall-clock time: the suite is mocked end to end and finishes in about a second either way. What it buys is the -race step actually exercising concurrency. Until now every test ran alone, so the detector was watching a serial program and the mutex the package runner grew when the seam moved onto the context was never exercised by anything. It is now, along with the concurrent readers of the mask registry.

The three files left behind are the ones that set the mask registry directly - properties_test.go, service_create_task_test.go and scheduler_k3s_autoscaling_auth_task_test.go. Isolating the registry per test is #501; they keep SetExecRunner until then, which is also what keeps that seam alive for the commands package.

Two tests needed more than the mechanical change. exportResource performs the ExportRecipe call for its callers, so it takes their context rather than building its own. And the two context-propagation tests build a context that carries a sentinel or a cancellation, so the runner goes onto that context instead of a fresh one - which is the more honest shape anyway, since the point of both is that the caller's context is the one that reaches the probe.

Verified with -shuffle=on across seeds and at -parallel 32, both under -race.

First of the two passes in #502. The commands half needs #501, #505 and #506 first.

Twenty-six of the twenty-nine `tasks` unit test files installed their fake executor by swapping a package variable, which is why nothing in this repo could call `t.Parallel()`. They now build the fake into the context they already pass to `Plan` and `Execute`, through `subprocess.ContextWithRunner`, and every test in those files runs in parallel - 149 call sites, 280 tests.

This buys no wall-clock time: the suite is mocked end to end and finishes in about a second either way. What it buys is the `-race` step actually exercising concurrency. Until now every test ran alone, so the detector was watching a serial program and the mutex the package runner grew when the seam moved onto the context was never exercised by anything. It is now, along with the concurrent readers of the mask registry.

The three files left behind are the ones that set the mask registry directly - `properties_test.go`, `service_create_task_test.go` and `scheduler_k3s_autoscaling_auth_task_test.go`. Isolating the registry per test is #501; they keep `SetExecRunner` until then, which is also what keeps that seam alive for the `commands` package.

Two tests needed more than the mechanical change. `exportResource` performs the `ExportRecipe` call for its callers, so it takes their context rather than building its own. And the two context-propagation tests build a context that carries a sentinel or a cancellation, so the runner goes onto that context instead of a fresh one - which is the more honest shape anyway, since the point of both is that the caller's context is the one that reaches the probe.

Verified with `-shuffle=on` across seeds and at `-parallel 32`, both under `-race`.
@josegonzalez
josegonzalez merged commit feb0797 into main Sep 2, 2026
19 checks passed
@josegonzalez
josegonzalez deleted the 502-tasks-unit-tests-parallel branch September 2, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant