claim invariant: run the read and nonApp probes in parallel
The probes group (~154 probes, about 73s) now runs its probes as parallel subtests too, bounded by the same claimCaseParallelism, after every door has finished. A probe that touches process-wide state carries claimProbe.serial with the reason and runs alone before the parallel ones start: - every claimLogWorkerProbe (captures the process log output), - PUT and DELETE /api/cli/system/geoip (withFixtureProbes swaps geoipProbeAddrs), - GET .../relay (relayEnabled uses t.Setenv). runClaimProbes takes the bound; TestClaimRegionHAEntriesAreProbed passes 0 and stays serial. Probe subtest names are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+50
−14
internal/console/claim_invariant_probes_nonapp_test.go+3 −1internal/console/claim_invariant_probes_read_test.go+3 −2internal/console/claim_invariant_probes_test.go+36 −5internal/console/claim_invariant_probes_worker_test.go+2 −1internal/console/claim_invariant_regionha_test.go+1 −1internal/console/claim_invariant_test.go+5 −4
diff --git a/internal/console/claim_invariant_probes_nonapp_test.go b/internal/console/claim_invariant_probes_nonapp_test.go| index 9e7c1697e..2cf291f75 100644 |
| --- a/internal/console/claim_invariant_probes_nonapp_test.go |
| +++ b/internal/console/claim_invariant_probes_nonapp_test.go |
| @@ -814,7 +814,8 @@ var claimNonAppProbes = map[string]claimProbe{ |
| }, |
| }, |
| "route PUT /api/cli/system/geoip": { |
| - setup: func(t *testing.T, cx *claimCase) { withFixtureProbes(t) }, |
| + serial: "withFixtureProbes swaps the package variable geoipProbeAddrs", |
| + setup: func(t *testing.T, cx *claimCase) { withFixtureProbes(t) }, |
| do: func(t *testing.T, cx *claimCase) claimReply { |
| return cx.apiReply(t, http.MethodPut, "/api/cli/system/geoip", string(fixture(t, "GeoIP2-City-Test.mmdb"))) |
| }, |
| @@ -834,6 +835,7 @@ var claimNonAppProbes = map[string]claimProbe{ |
| }, |
| }, |
| "route DELETE /api/cli/system/geoip": { |
| + serial: "withFixtureProbes swaps the package variable geoipProbeAddrs", |
| setup: func(t *testing.T, cx *claimCase) { |
| withFixtureProbes(t) |
| if _, err := cx.srv.geoip.Publish(context.Background(), strings.NewReader(string(fixture(t, "GeoIP2-City-Test.mmdb"))), geoipPublishOpts{Origin: "manual"}); err != nil { |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 307543163..52f07645d 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -200,8 +200,9 @@ var claimReadProbes = map[string]claimProbe{ |
| "/api/cli/apps/bab/titogo/pending", "<pending>"), |
| "route GET /api/cli/apps/{account}/{app}/pipeline": claimAPIRead(nil, "/api/cli/apps/bab/titogo/pipeline", `"pipeline"`), |
| "route GET /api/cli/apps/{account}/{app}/regions": claimAPIRead(nil, "/api/cli/apps/bab/titogo/regions", `"regions"`), |
| - "route GET /api/cli/apps/{account}/{app}/relay": claimAPIRead(func(t *testing.T, cx *claimCase) { cx.relayEnabled(t) }, |
| - "/api/cli/apps/bab/titogo/relay", `"app":"titogo"`, `"enabled":true`), |
| + "route GET /api/cli/apps/{account}/{app}/relay": claimSerialProbe("relayEnabled stages the region's relay master through t.Setenv: process environment", |
| + claimAPIRead(func(t *testing.T, cx *claimCase) { cx.relayEnabled(t) }, |
| + "/api/cli/apps/bab/titogo/relay", `"app":"titogo"`, `"enabled":true`)), |
| "route GET /api/cli/apps/{account}/{app}/releases": claimAPIRead(nil, "/api/cli/apps/bab/kass/releases", `"version":"v1"`), |
| "route GET /api/cli/apps/{account}/{app}/releases/{version}/authorize": claimAPIRead(nil, |
| "/api/cli/apps/bab/kass/releases/v1/authorize", `"version":"v1"`, `"manifest_digest":"`), |
diff --git a/internal/console/claim_invariant_probes_test.go b/internal/console/claim_invariant_probes_test.go| index 3e1ed8121..44ffe1b2d 100644 |
| --- a/internal/console/claim_invariant_probes_test.go |
| +++ b/internal/console/claim_invariant_probes_test.go |
| @@ -80,6 +80,16 @@ type claimProbe struct { |
| // effect proves from the world that the handler did its work, and returns |
| // "" when it did. It is required for every nonApp entry. |
| effect func(t *testing.T, cx *claimCase, r claimReply) string |
| + // serial, when set, says why this probe touches process-wide state (the |
| + // environment, the log output, a package variable). Such a probe runs |
| + // alone, before any parallel probe starts. |
| + serial string |
| +} |
| + |
| +// claimSerialProbe marks p serial, with the reason. |
| +func claimSerialProbe(reason string, p claimProbe) claimProbe { |
| + p.serial = reason |
| + return p |
| } |
| // claimWatched are the apps whose SQL and bucket state every probe must leave |
| @@ -417,18 +427,39 @@ func claimProbeKeys(fixtures map[string]claimFixture) []string { |
| // runClaimProbes runs every read and nonApp probe on its own console, so no |
| // probe's world (a closed session, a deleted account) disturbs another's. |
| -func runClaimProbes(t *testing.T, fixtures map[string]claimFixture, probes map[string]claimProbe, opts ...func(*Config)) { |
| +// With parallel above zero, at most that many run at once; a serial probe |
| +// still runs alone, before the parallel ones start (they wait until this |
| +// function returns). The caller's t.Run returns when all of them are done. |
| +func runClaimProbes(t *testing.T, fixtures map[string]claimFixture, probes map[string]claimProbe, parallel int, opts ...func(*Config)) { |
| t.Helper() |
| + run := func(t *testing.T, key string, p claimProbe) { |
| + cx := newClaimCaseWith(t, opts...) |
| + for _, problem := range runClaimProbe(t, cx, key, p) { |
| + t.Error(problem) |
| + } |
| + } |
| + var deferred []string |
| for _, key := range claimProbeKeys(fixtures) { |
| p, ok := probes[key] |
| if !ok { |
| continue // the census names it |
| } |
| + if parallel > 0 && strings.TrimSpace(p.serial) == "" { |
| + deferred = append(deferred, key) |
| + continue |
| + } |
| + t.Run(key, func(t *testing.T) { run(t, key, p) }) |
| + } |
| + slots := make(chan struct{}, max(parallel, 1)) |
| + for _, key := range deferred { |
| + p := probes[key] |
| t.Run(key, func(t *testing.T) { |
| - cx := newClaimCaseWith(t, opts...) |
| - for _, problem := range runClaimProbe(t, cx, key, p) { |
| - t.Error(problem) |
| - } |
| + t.Parallel() |
| + slots <- struct{}{} |
| + // Registered first, so it runs last: the slot is held until the |
| + // case's own cleanup (servers, store) is done. |
| + t.Cleanup(func() { <-slots }) |
| + run(t, key, p) |
| }) |
| } |
| } |
diff --git a/internal/console/claim_invariant_probes_worker_test.go b/internal/console/claim_invariant_probes_worker_test.go| index c75eb79e2..c04aa439d 100644 |
| --- a/internal/console/claim_invariant_probes_worker_test.go |
| +++ b/internal/console/claim_invariant_probes_worker_test.go |
| @@ -32,7 +32,8 @@ import ( |
| // it must have said about a real finding. |
| func claimLogWorkerProbe(name string, setup func(*testing.T, *claimCase), want ...string) claimProbe { |
| return claimProbe{ |
| - setup: setup, |
| + serial: "captures the process-wide log output (captureLogTo): another case's log lines would land in its answer", |
| + setup: setup, |
| do: func(t *testing.T, cx *claimCase) claimReply { |
| var logs strings.Builder |
| restore := captureLogTo(&logs) |
diff --git a/internal/console/claim_invariant_regionha_test.go b/internal/console/claim_invariant_regionha_test.go| index a8e5dcfc9..f1c797977 100644 |
| --- a/internal/console/claim_invariant_regionha_test.go |
| +++ b/internal/console/claim_invariant_regionha_test.go |
| @@ -158,5 +158,5 @@ func TestClaimRegionHAConsoleRouteCensus(t *testing.T) { |
| // TestClaimRegionHAEntriesAreProbed drives every region-HA-only entry's |
| // probe on a console built with region HA on. |
| func TestClaimRegionHAEntriesAreProbed(t *testing.T) { |
| - runClaimProbes(t, claimRegionHAFixtures, claimRegionHAProbes, claimRegionHAOn) |
| + runClaimProbes(t, claimRegionHAFixtures, claimRegionHAProbes, 0, claimRegionHAOn) |
| } |
diff --git a/internal/console/claim_invariant_test.go b/internal/console/claim_invariant_test.go| index 183f014b9..305137b6c 100644 |
| --- a/internal/console/claim_invariant_test.go |
| +++ b/internal/console/claim_invariant_test.go |
| @@ -179,8 +179,8 @@ var claimCoordinators = map[string]string{ |
| "and the function's own writes reach Put, Delete or DeleteIfMatch)", |
| } |
| -// claimCaseParallelism bounds how many door and refusal subtests run at |
| -// once. Each one builds its own console and measures what a request left |
| +// claimCaseParallelism bounds how many door, refusal and probe subtests run |
| +// at once. Each one builds its own console and measures what a request left |
| // behind by waiting for quiet windows (quiesce). Too many at once starve the |
| // CPU, and a handler goroutine that misses its window is measured with the |
| // wrong request; the bound keeps that contention down. |
| @@ -313,9 +313,10 @@ func TestClaimConsoleMutationInvariant(t *testing.T) { |
| // Reads and nonApp entries are probed with their own valid request on |
| // their own console (claim_invariant_probes_test.go): a request the |
| // handler turned away is not coverage, and a mutator proves its effect |
| - // from the world. |
| + // from the world. They run in parallel too, after every door, except the |
| + // probes marked serial (claimProbe.serial), which run alone first. |
| t.Run("probes", func(t *testing.T) { |
| - runClaimProbes(t, claimFixtures, claimProbes) |
| + runClaimProbes(t, claimFixtures, claimProbes, claimCaseParallelism) |
| }) |
| var unreached []string |