claim invariant: three more fixtures serial, and a guard for the next one (Astra)
Astra P3: StartMailEventPush swaps mailPushClient.Transport, the StartHostReports probe swaps hostRunningImage, and the GeoIP GET probe swaps geoipProbeAddrs (claimWorldGeoip), but none was listed serial. All three are now. The census of serial entries could only check listed names, not find missing ones. claimParallelCases counts the claim cases running under t.Parallel, and claimMustRunAlone, called at every swap of process-wide state in these fixtures (the three above, both geoip probes, and the log worker probes), fails a case that runs beside any parallel case, itself included. Dropping StartHostReports' serial reason now fails with "swaps process-wide state but runs beside 1 parallel claim case(s)".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+42
−10
internal/console/claim_invariant_fixtures_test.go+1 −0internal/console/claim_invariant_probes_nonapp_test.go+2 −1internal/console/claim_invariant_probes_read_test.go+6 −1internal/console/claim_invariant_probes_test.go+1 −4internal/console/claim_invariant_probes_worker_test.go+3 −0internal/console/claim_invariant_test.go+29 −4
CI passed — run details
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index d09d1d291..8919640e9 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -1876,6 +1876,7 @@ var claimFixtures = map[string]claimFixture{ |
| "worker StartMailEventPush": {door: &claimDoor{ |
| apps: claimRefs("bab/titogo"), |
| setup: func(t *testing.T, cx *claimCase) { |
| + claimMustRunAlone(t, "worker StartMailEventPush") |
| old := mailPushClient.Transport |
| mailPushClient.Transport = claimOKTransport{rec: cx.rec} |
| t.Cleanup(func() { mailPushClient.Transport = old }) |
diff --git a/internal/console/claim_invariant_probes_nonapp_test.go b/internal/console/claim_invariant_probes_nonapp_test.go| index 2cf291f75..8e16fe554 100644 |
| --- a/internal/console/claim_invariant_probes_nonapp_test.go |
| +++ b/internal/console/claim_invariant_probes_nonapp_test.go |
| @@ -815,7 +815,7 @@ var claimNonAppProbes = map[string]claimProbe{ |
| }, |
| "route PUT /api/cli/system/geoip": { |
| serial: "withFixtureProbes swaps the package variable geoipProbeAddrs", |
| - setup: func(t *testing.T, cx *claimCase) { withFixtureProbes(t) }, |
| + setup: func(t *testing.T, cx *claimCase) { claimMustRunAlone(t, "geoip probe"); 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"))) |
| }, |
| @@ -837,6 +837,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) { |
| + claimMustRunAlone(t, "geoip probe") |
| withFixtureProbes(t) |
| if _, err := cx.srv.geoip.Publish(context.Background(), strings.NewReader(string(fixture(t, "GeoIP2-City-Test.mmdb"))), geoipPublishOpts{Origin: "manual"}); err != nil { |
| t.Fatalf("stage a published geoip database: %v", err) |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 52f07645d..5c814388d 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -84,6 +84,7 @@ func claimWorldApply(t *testing.T, cx *claimCase) { |
| func claimWorldGeoip(t *testing.T, cx *claimCase) { |
| t.Helper() |
| + claimMustRunAlone(t, "claimWorldGeoip") |
| withFixtureProbes(t) |
| if _, err := cx.srv.geoip.Publish(context.Background(), bytes.NewReader(fixture(t, "GeoIP2-City-Test.mmdb")), geoipPublishOpts{Origin: "manual"}); err != nil { |
| t.Fatalf("stage a published geoip database: %v", err) |
| @@ -233,7 +234,11 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /api/cli/accounts/{account}/plan": claimAPIRead(func(t *testing.T, cx *claimCase) { cx.srv.cfg.PlanCatalog = examplePlanCatalog(t) }, |
| "/api/cli/accounts/bab/plan", `"plan":"free"`), |
| "route GET /api/cli/system/antivirus": claimAPIRead(nil, "/api/cli/system/antivirus", `"wired":true`), |
| - "route GET /api/cli/system/geoip": claimAPIRead(claimWorldGeoip, "/api/cli/system/geoip", `"pointer"`, "GeoIP2-City"), |
| + "route GET /api/cli/system/geoip": func() claimProbe { |
| + p := claimAPIRead(claimWorldGeoip, "/api/cli/system/geoip", `"pointer"`, "GeoIP2-City") |
| + p.serial = "claimWorldGeoip swaps the package variable geoipProbeAddrs (withFixtureProbes)" |
| + return p |
| + }(), |
| "route GET /api/cli/system/jobs/{id}": { |
| setup: func(t *testing.T, cx *claimCase) { cx.vars["job"] = cx.systemRelease(t, "canary", "66587fa") }, |
| do: claimGetAPI("/api/cli/system/jobs/<job>"), |
diff --git a/internal/console/claim_invariant_probes_test.go b/internal/console/claim_invariant_probes_test.go| index 44ffe1b2d..77914218c 100644 |
| --- a/internal/console/claim_invariant_probes_test.go |
| +++ b/internal/console/claim_invariant_probes_test.go |
| @@ -455,10 +455,7 @@ func runClaimProbes(t *testing.T, fixtures map[string]claimFixture, probes map[s |
| p := probes[key] |
| t.Run(key, func(t *testing.T) { |
| 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 }) |
| + claimParallelSlot(t, 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 c04aa439d..765f8db9a 100644 |
| --- a/internal/console/claim_invariant_probes_worker_test.go |
| +++ b/internal/console/claim_invariant_probes_worker_test.go |
| @@ -35,6 +35,7 @@ func claimLogWorkerProbe(name string, setup func(*testing.T, *claimCase), want . |
| 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 { |
| + claimMustRunAlone(t, "log worker probe "+name) |
| var logs strings.Builder |
| restore := captureLogTo(&logs) |
| reply := claimWorkerReply(name)(t, cx) |
| @@ -156,7 +157,9 @@ var claimWorkerProbes = map[string]claimProbe{ |
| }, |
| }, |
| "worker StartHostReports": { |
| + serial: "swaps the package variable hostRunningImage", |
| setup: func(t *testing.T, cx *claimCase) { |
| + claimMustRunAlone(t, "worker StartHostReports") |
| // The box's guard files are not here; the seam says what this |
| // process is running, as the guard would. |
| prev := hostRunningImage |
diff --git a/internal/console/claim_invariant_test.go b/internal/console/claim_invariant_test.go| index 305137b6c..5e438dd64 100644 |
| --- a/internal/console/claim_invariant_test.go |
| +++ b/internal/console/claim_invariant_test.go |
| @@ -54,6 +54,7 @@ import ( |
| "sort" |
| "strings" |
| "sync" |
| + "sync/atomic" |
| "testing" |
| "time" |
| @@ -186,6 +187,32 @@ var claimCoordinators = map[string]string{ |
| // wrong request; the bound keeps that contention down. |
| const claimCaseParallelism = 8 |
| +// claimParallelCases counts the claim cases running under t.Parallel. A |
| +// fixture that swaps process-wide state (a package variable, the log |
| +// output, a shared client's transport) calls claimMustRunAlone, which |
| +// fails the case if any parallel case is running, itself included. A swap |
| +// added to a fixture that is not listed serial therefore fails loudly |
| +// instead of leaking into a neighbour's measurement. |
| +var claimParallelCases atomic.Int32 |
| + |
| +func claimMustRunAlone(t *testing.T, what string) { |
| + t.Helper() |
| + if n := claimParallelCases.Load(); n > 0 { |
| + t.Fatalf("%s swaps process-wide state but runs beside %d parallel claim case(s): list it serial (claimSerialDoors, or the probe's serial field)", what, n) |
| + } |
| +} |
| + |
| +// claimParallelSlot takes a slot for a parallel claim case and counts it |
| +// as running until its own cleanup is done. |
| +func claimParallelSlot(t *testing.T, slots chan struct{}) { |
| + 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 }) |
| + claimParallelCases.Add(1) |
| + t.Cleanup(func() { claimParallelCases.Add(-1) }) |
| +} |
| + |
| // claimSerialDoors are the door and refusal fixtures that must not run in |
| // parallel, each with the reason. They run first, one at a time, before any |
| // parallel door starts. A fixture whose staging touches process-wide state |
| @@ -201,6 +228,7 @@ var claimSerialDoors = map[string]string{ |
| "process environment, which t.Parallel forbids", |
| "worker StartRelay": "relayEnabled stages the region's relay master through t.Setenv: " + |
| "process environment, which t.Parallel forbids", |
| + "worker StartMailEventPush": "swaps mailPushClient.Transport, a package variable, for its recorder", |
| } |
| // claimSerialDoorCensus: every serial entry names a door or refusal fixture |
| @@ -295,10 +323,7 @@ func TestClaimConsoleMutationInvariant(t *testing.T) { |
| if f := claimFixtures[key]; (f.door != nil || f.refused != nil) && claimSerialDoors[key] == "" { |
| t.Run(key, func(t *testing.T) { |
| 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 }) |
| + claimParallelSlot(t, slots) |
| run(t, f) |
| }) |
| } |