carlos / platform Public

activator tests: join wakes before restoring knobs; add to -race

Tests shrank a package-level timing setting and put it back in a
t.Cleanup while the wake they started could still read it, which is a
data race under -race. Production never changes these settings, so
only the tests change.

restoreKnob (knobrestore_test.go) replaces those cleanups. It waits
until no production goroutine from the test is still running, then
synchronises with each Service built through newTrackedService, then
restores. The synchronisation is needed as well as the wait: seeing a
goroutine gone from the stacks is not an ordering the race detector
accepts, and it still reported finished wakes against the restore.

TestDrainStopUnprovenKeepsTheLease left a stop pending for ever; it now
lets the unit go and waits for that stop as it ends.

internal/activator joins the 70-race step on 8 shards. internal/lease
stays out until the litestream upgrade.

Refs #1249
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a4a18542e5f2dccc747546a76610a9a528e1654a parent 0e0dec7
94 files changed, +446 −228
  • .amadan/README.md +5 −10
  • .amadan/ci.d/70-race +6 −11
  • .amadan/test-gate.sh +1 −1
  • AGENTS.md +6 −4
  • internal/activator/activator_test.go +8 −8
  • internal/activator/backend_exec_test.go +9 −9
  • internal/activator/backend_unit_test.go +4 −4
  • internal/activator/binary_golden_test.go +1 −1
  • internal/activator/canonlink_test.go +1 −1
  • internal/activator/claimgen_test.go +2 −2
  • internal/activator/claimloop_linux_test.go +1 −1
  • internal/activator/claimrecord_linux_test.go +1 −1
  • internal/activator/cmd_test.go +1 −1
  • internal/activator/cmdunit_test.go +1 −1
  • internal/activator/containment_test.go +1 −1
  • internal/activator/demo_durability_test.go +3 −3
  • internal/activator/escrow_test.go +3 −3
  • internal/activator/exec_gate_test.go +2 −2
  • internal/activator/generations_instances_test.go +1 −1
  • internal/activator/genservice_test.go +1 −1
  • internal/activator/group_admission_test.go +4 −4
  • internal/activator/ha_pool_test.go +2 −2
  • internal/activator/haadopt_test.go +4 −4
  • internal/activator/hadrain_test.go +1 −1
  • internal/activator/hadrainmove_test.go +10 −0
  • internal/activator/haescrow_branchfix_test.go +1 −1
  • internal/activator/hafiles_test.go +2 −2
  • internal/activator/haforward_test.go +5 −5
  • internal/activator/haleaseloss_test.go +4 −4
  • internal/activator/handover_test.go +1 −1
  • internal/activator/haplacement_test.go +3 −3
  • internal/activator/harelease_test.go +3 −3
  • internal/activator/hasecrets_test.go +1 −1
  • internal/activator/hasuspect_test.go +6 −6
  • internal/activator/hatake_test.go +3 −3
  • internal/activator/hawake_test.go +2 −2
  • internal/activator/heldstream_e2e_test.go +1 −1
  • internal/activator/instancekey_test.go +1 −1
  • internal/activator/knobrestore_test.go +216 −0
  • internal/activator/maintenance_test.go +1 −1
  • internal/activator/opset_test.go +4 −4
  • internal/activator/outcome_fence_test.go +1 −1
  • internal/activator/pendingwake_linux_test.go +3 −3
  • internal/activator/probewake_test.go +5 −5
  • internal/activator/production_backend_test.go +1 −1
  • internal/activator/pty_linux_test.go +1 −1
  • internal/activator/replica_drill1_test.go +2 −2
  • internal/activator/replica_install_wait_test.go +1 −1
  • internal/activator/replicadeploy_test.go +5 −5
  • internal/activator/replicaswitchfail_test.go +1 −1
  • internal/activator/retire_refuse_e2e_test.go +1 −1
  • internal/activator/rootfs_admission_test.go +1 −1
  • internal/activator/rootfs_cmd_lease_test.go +2 −2
  • internal/activator/rootfs_cmd_test.go +2 −2
  • internal/activator/rootfs_gate_test.go +1 −1
  • internal/activator/rootfs_invariants_test.go +5 −5
  • internal/activator/rootfs_processes_test.go +1 −1
  • internal/activator/rootfs_release_backend_test.go +1 −1
  • internal/activator/rootfs_resident_lease_test.go +2 −2
  • internal/activator/rootfs_resident_test.go +1 −1
  • internal/activator/rootfs_staged_test.go +2 −2
  • internal/activator/rootfs_swap_release_test.go +1 −1
  • internal/activator/rootfs_test.go +4 −4
  • internal/activator/rootfs_wake_release_test.go +1 −1
  • internal/activator/rootfsdb_test.go +2 −2
  • internal/activator/rootfsrelease_test.go +4 −4
  • internal/activator/rootfsworkers_backend_test.go +1 −1
  • internal/activator/rootfsworkers_test.go +4 −4
  • internal/activator/seedplace_linux_test.go +2 −2
  • internal/activator/settle_test.go +2 −2
  • internal/activator/shuttingdown_answer_test.go +1 −1
  • internal/activator/size_live_test.go +1 −1
  • internal/activator/startrule_test.go +2 −2
  • internal/activator/startup_test.go +7 −7
  • internal/activator/stop_returned_sidecar_test.go +1 −1
  • internal/activator/swap_admit_test.go +2 −2
  • internal/activator/swap_fixture_test.go +1 −1
  • internal/activator/swap_hold_test.go +2 −2
  • internal/activator/swap_review_test.go +2 −2
  • internal/activator/swap_sim_test.go +2 −2
  • internal/activator/tunnel_refuse_test.go +2 −2
  • internal/activator/unitproc_test.go +1 −1
  • internal/activator/wakecheck_claim_linux_test.go +1 −1
  • internal/activator/wakecheck_test.go +3 −3
  • internal/activator/wakeidentity_test.go +3 −3
  • internal/activator/wakeplan_test.go +8 −8
  • internal/activator/wakerecord_refused_test.go +1 −1
  • internal/activator/wakeslots_test.go +1 −1
  • internal/activator/worker_gen_test.go +3 −3
  • internal/activator/worker_generations_test.go +2 −2
  • internal/activator/worker_identity_test.go +1 −1
  • internal/activator/worker_respawn_exec_test.go +1 −1
  • internal/activator/worker_retained_pin_test.go +1 −1
  • internal/activator/workerswap_test.go +4 −4

CI cancelled — superseded by a newer push — run details

diff --git a/.amadan/README.md b/.amadan/README.md
index 622b31f8a..c9adfb9b6 100644
--- a/.amadan/README.md
+++ b/.amadan/README.md
@@ -45,7 +45,7 @@ detector on 2026-11-17.
| `govulncheck` | `50-govulncheck` | `make govulncheck`: v1.8.0 over this module and `launchctx`; fails only on vulnerabilities the code calls, less the exceptions file; see below |
| code-health gate | `60-code-health` | `make code-health`: the code against `.amadan/code-health.tsv`, scanned with type information; see below |
| code-health record | `61-code-health-record` | the record against the merge base's copy; see below |
-| race detector | `70-race` | `make race`: `go test -race` over the edge, rootaws and systemd packages and host's loop and lease tests, sharded like the gate; see below |
+| race detector | `70-race` | `make race`: `go test -race` over the edge, activator, rootaws and systemd packages and host's loop and lease tests, sharded like the gate; see below |
## `govulncheck`: what turns it red
@@ -123,8 +123,8 @@ dealt onto shards by `test-weights.tsv` and held by the same fence as
packages are the ones with real concurrency: every test of
`internal/edge` (less `TestLinkPinForwardedFallback`, `RACE_SKIP`: its
ten bcrypt logins outlast the rate-limit window under `-race`),
-`internal/rootaws` and `internal/systemd`, and of `internal/host` the
-tests named for a loop or a lease (`RACE_ONLY`). The whole host suite under `-race` is far past
+`internal/activator`, `internal/rootaws` and `internal/systemd`, and of
+`internal/host` the tests named for a loop or a lease (`RACE_ONLY`). The whole host suite under `-race` is far past
the step's budget: measured once on docs-t1 (16 cores, `GOMAXPROCS=4`,
the machine otherwise busy), every host shard ran past fifteen minutes.
The link simulations run fewer seeds here (`LINKSIM_SEEDS`); `make test`
@@ -132,13 +132,8 @@ runs them at full breadth. It is its own
step because `-race` compiles those packages again and runs their tests
several times slower.
-Three packages are left out. The root package's e2e tests build the CLI
-many times over and are too slow under `-race`. `internal/activator` has
-45 tests that shrink a package-level timing knob and restore it in a
-cleanup while the wake they started is still running, so the restore
-races the wake's read. Production never changes those knobs; the fix is
-for the tests to wait for their wakes, or for the knobs to stop being
-plain variables, and the package joins the step then. `internal/lease` trips a
+Two packages are left out. The root package's e2e tests build the CLI
+many times over and are too slow under `-race`. `internal/lease` trips a
race inside litestream v0.5.14: `Store.Close` closes the database while
the store's own snapshot monitor is still reading it. Upstream fixed it
in v0.5.18 (`Store.Close` now stops its monitors first); lease joins the
diff --git a/.amadan/ci.d/70-race b/.amadan/ci.d/70-race
index f8396bbb4..054f963f2 100755
--- a/.amadan/ci.d/70-race
+++ b/.amadan/ci.d/70-race
@@ -1,14 +1,15 @@
#!/bin/sh
# The race detector over the packages with real concurrency: the edge
-# (servers, pollers, the tunnel), the host agent's loops and lease handling, and the two packages those
-# loops call into for AWS and systemd, internal/rootaws and
-# internal/systemd. `make race` is the one definition; this step only
-# runs it, so a developer gets the same answer with the same command.
+# (servers, pollers, the tunnel), the activator (wakes, stops, swaps), the
+# host agent's loops and lease handling, and the two packages those loops
+# call into for AWS and systemd, internal/rootaws and internal/systemd.
+# `make race` is the one definition; this step only runs it, so a developer
+# gets the same answer with the same command.
#
# The tests in those packages, with -race, dealt onto shards and fenced by
# .amadan/test-gate.sh exactly as `make test` deals its own (GATE_RACE=1;
# RACE_SPLIT in that file names the packages and how many shards each).
-# Every test of edge, rootaws and systemd, less one (RACE_SKIP); of
+# Every test of edge, activator, rootaws and systemd, less one (RACE_SKIP); of
# internal/host only the tests named for a loop or a lease (RACE_ONLY),
# because its whole suite under -race is far past this step's budget.
# Its own step, not part of 10-gate: -race compiles the packages again and
@@ -18,12 +19,6 @@
# Left out, each for a reason:
# - the root package: its e2e tests build the CLI many times over, too
# slow under -race;
-# - internal/activator: 45 tests shrink a package-level timing knob and
-# put it back in a cleanup while the wake they started is still
-# running, so the restore races the wake's read. The race is in how
-# the tests end, not in production, where the knobs never change. It
-# joins this step once those tests wait for their wakes, or the knobs
-# stop being plain variables;
# - internal/lease: litestream v0.5.14's Store.Close closes the database
# while its own snapshot monitor still reads it (a race inside the
# dependency, fixed upstream in v0.5.18, which stops the monitors
diff --git a/.amadan/test-gate.sh b/.amadan/test-gate.sh
index b693b60c8..3f3d149dd 100755
--- a/.amadan/test-gate.sh
+++ b/.amadan/test-gate.sh
@@ -69,7 +69,7 @@ race=""
if [ "${GATE_RACE:-}" = 1 ]; then
# The packages with real concurrency (.amadan/ci.d/70-race says why
# these and not the rest), heaviest first like TEST_SPLIT.
- : "${RACE_SPLIT=./internal/edge=16 ./internal/host=2 ./internal/rootaws=1 ./internal/systemd=1}"
+ : "${RACE_SPLIT=./internal/edge=16 ./internal/activator=8 ./internal/host=2 ./internal/rootaws=1 ./internal/systemd=1}"
# internal/host's whole suite under -race is far past the step's
# budget (every shard ran past fifteen minutes on a 16-core box), so
# only its loops and its lease handling: the tests named for them.
diff --git a/AGENTS.md b/AGENTS.md
index 94cd29d99..4973080c3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -295,15 +295,17 @@ anything.
anything. Imported-only and required-only findings are printed, not
fatal. It needs `vuln.go.dev` and the module proxy; `.amadan/README.md`
has the details.
-- `70-race` runs `make race`: `internal/edge`, `internal/rootaws`,
- `internal/systemd` and `internal/host`'s tests named for a loop or a
+- `70-race` runs `make race`: `internal/edge`, `internal/activator`,
+ `internal/rootaws`, `internal/systemd` and `internal/host`'s tests named for a loop or a
lease, under `-race`, sharded by `.amadan/test-gate.sh` (`GATE_RACE=1`,
`RACE_SPLIT`, `RACE_ONLY`, `RACE_SKIP`). It needs cgo and a C compiler. A test
in edge, activator or host that reads the standard log uses its
package's `captureLog` (a locked buffer; host also has
`captureLogBuffer`), never a plain `bytes.Buffer`, and a goroutine a
- test starts ends before the test does. `internal/activator` and
- `internal/lease` are out for now (`.amadan/README.md` says why).
+ test starts ends before the test does. An activator test that changes
+ a package-level setting puts it back with `restoreKnob` and builds its
+ Service with `newTrackedService`, so the restore waits for the test's
+ wakes. `internal/lease` is out for now (`.amadan/README.md` says why).
- `20-cross@5` adds `GOOS=darwin`/`windows`/`linux-arm64` compiles, one
per shard. **The gate is not Linux-only**: `internal/host` is linked
into the CLI, which people run on Macs, so a Linux-only type assumption
diff --git a/internal/activator/activator_test.go b/internal/activator/activator_test.go
index 4519b8e56..42e1dd3b9 100644
--- a/internal/activator/activator_test.go
+++ b/internal/activator/activator_test.go
@@ -897,7 +897,7 @@ func testActivator(t *testing.T, idle time.Duration) (*Service, *fakeBackend, *f
if err != nil {
t.Fatalf("open registry: %v", err)
}
- a := New(Config{Bucket: "test-bucket", Idle: idle}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: idle}, b, reg)
a.now = clk.now
return a, b, clk, reg
}
@@ -2011,7 +2011,7 @@ func TestActivatorWakeTimeout(t *testing.T) {
a, b, _, _ := testActivator(t, time.Minute)
old := wakeWaitBound
wakeWaitBound = 100 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
gate := make(chan struct{})
b.startGate = gate
@@ -2835,7 +2835,7 @@ func TestActivatorDueSurvivesRestart(t *testing.T) {
// "Restart": a fresh activator, same registry.
b2 := &fakeBackend{}
- a2 := New(Config{Bucket: "test-bucket", Idle: 10 * time.Second}, b2, reg)
+ a2 := newTrackedService(Config{Bucket: "test-bucket", Idle: 10 * time.Second}, b2, reg)
a2.now = clk.now
clk.advance(25 * time.Second) // past the due time
@@ -5924,7 +5924,7 @@ func swapRestoreReplica(t *testing.T, fn func(ctx context.Context, dbPath, bucke
t.Helper()
prev := restoreReplica
restoreReplica = fn
- t.Cleanup(func() { restoreReplica = prev })
+ restoreKnob(t, func() { restoreReplica = prev })
}
// The seed contract, end to end through a real exec: the app's declared argv
@@ -6073,7 +6073,7 @@ func TestExecBackendSeedIsTimeBounded(t *testing.T) {
prevTimeout, prevGrace := seedTimeout, seedDrainGrace
seedTimeout, seedDrainGrace = 200*time.Millisecond, 200*time.Millisecond
- t.Cleanup(func() { seedTimeout, seedDrainGrace = prevTimeout, prevGrace })
+ restoreKnob(t, func() { seedTimeout, seedDrainGrace = prevTimeout, prevGrace })
start := time.Now()
err := b.Seed(context.Background(), registry.Route{Host: host, Kind: "instance", Seed: `["seed"]`})
@@ -6157,7 +6157,7 @@ func TestExecBackendSeedSucceedsDespiteLingeringChild(t *testing.T) {
prevTimeout, prevGrace := seedTimeout, seedDrainGrace
seedTimeout, seedDrainGrace = 10*time.Second, 200*time.Millisecond
- t.Cleanup(func() { seedTimeout, seedDrainGrace = prevTimeout, prevGrace })
+ restoreKnob(t, func() { seedTimeout, seedDrainGrace = prevTimeout, prevGrace })
if err := b.Seed(context.Background(), registry.Route{Host: host, Kind: "instance", Seed: `["seed"]`}); err != nil {
t.Fatalf("Seed = %v, want nil — the seed exited 0; a leaked output pipe is not a failed seed", err)
@@ -6918,7 +6918,7 @@ func TestDoWakeRefreshesTheRouteFromTheRegistry(t *testing.T) {
func TestAStopKeepsTheLeaseUntilAnInFlightSidecarStartReturns(t *testing.T) {
prev := sidecarStartJoinWait
sidecarStartJoinWait = 50 * time.Millisecond
- t.Cleanup(func() { sidecarStartJoinWait = prev })
+ restoreKnob(t, func() { sidecarStartJoinWait = prev })
a, b, _, _ := testActivator(t, time.Hour)
h := &hostEmptyFake{fakeBackend: b}
a.backend = h
@@ -7013,7 +7013,7 @@ func TestDoWakeRecordsSeedPlacementAfterReplication(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
rt := testRoute("shop.example.com")
rt.SeedSource = seeds.RowSeed{ID: "sd_aaaaaaaaaaaaaaaaaaaaaaaaaa", Kind: seeds.KindReplica, State: seeds.StateReady}.Encode()
if err := reg.Upsert(rt); err != nil {
diff --git a/internal/activator/backend_exec_test.go b/internal/activator/backend_exec_test.go
index b57119831..d1f31096c 100644
--- a/internal/activator/backend_exec_test.go
+++ b/internal/activator/backend_exec_test.go
@@ -632,7 +632,7 @@ func (r *recordingStrict) seen() []string {
func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 300 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
host := "strict.example.com"
// argvPath is the recorder's first file: once it exists and the child
// has exited, the health wait the recorder never answers is over.
@@ -851,7 +851,7 @@ func (f *flakyStrict) Close() error {
func TestStrictCleanupIsRetriedAndRefusesUntilItSucceeds(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 300 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
host := "retry.example.com"
for name, tc := range map[string]struct {
killFails, closeFails int
@@ -863,7 +863,7 @@ func TestStrictCleanupIsRetriedAndRefusesUntilItSucceeds(t *testing.T) {
t.Run(name, func(t *testing.T) {
oldBackoff := strictCleanupBackoff
strictCleanupBackoff = []time.Duration{400 * time.Millisecond, 400 * time.Millisecond}
- t.Cleanup(func() { strictCleanupBackoff = oldBackoff })
+ restoreKnob(t, func() { strictCleanupBackoff = oldBackoff })
b := testExecBackend(t)
b.Cgroups = delegatedManager(t)
b.strictPreflight = func() error { return nil }
@@ -943,7 +943,7 @@ func TestStrictCleanupIsRetriedAndRefusesUntilItSucceeds(t *testing.T) {
func TestStrictCleanupGivesUpButStaysRefused(t *testing.T) {
oldBackoff := strictCleanupBackoff
strictCleanupBackoff = []time.Duration{10 * time.Millisecond, 10 * time.Millisecond}
- t.Cleanup(func() { strictCleanupBackoff = oldBackoff })
+ restoreKnob(t, func() { strictCleanupBackoff = oldBackoff })
host := "stuck.example.com"
b := testExecBackend(t)
h := &flakyStrict{recordingStrict: newRecordingStrict(), killFails: 100}
@@ -1053,7 +1053,7 @@ func (d *dirStrict) Close() error {
func TestPendingStrictCleanupOwnsTheGroup(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 300 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
host := "owned.example.com"
for name, tc := range map[string]struct {
killFails, closeFails int
@@ -1065,7 +1065,7 @@ func TestPendingStrictCleanupOwnsTheGroup(t *testing.T) {
t.Run(name, func(t *testing.T) {
oldBackoff := strictCleanupBackoff
strictCleanupBackoff = []time.Duration{500 * time.Millisecond, 500 * time.Millisecond}
- t.Cleanup(func() { strictCleanupBackoff = oldBackoff })
+ restoreKnob(t, func() { strictCleanupBackoff = oldBackoff })
b := testExecBackend(t)
b.Cgroups = delegatedManager(t)
b.strictPreflight = func() error { return nil }
@@ -1203,7 +1203,7 @@ func hookAt(point string, fn func()) func(string) {
func TestAnOlderExitCannotRemoveANewOwnersGroup(t *testing.T) {
oldBackoff := strictCleanupBackoff
strictCleanupBackoff = []time.Duration{time.Hour}
- t.Cleanup(func() { strictCleanupBackoff = oldBackoff })
+ restoreKnob(t, func() { strictCleanupBackoff = oldBackoff })
host := "race.example.com"
b := testExecBackend(t)
b.Cgroups = delegatedManager(t)
@@ -1272,7 +1272,7 @@ func TestAnOlderExitCannotRemoveANewOwnersGroup(t *testing.T) {
func TestAPendingTransitionRacesARefusal(t *testing.T) {
oldBackoff := strictCleanupBackoff
strictCleanupBackoff = []time.Duration{time.Hour}
- t.Cleanup(func() { strictCleanupBackoff = oldBackoff })
+ restoreKnob(t, func() { strictCleanupBackoff = oldBackoff })
host := "transition.example.com"
b := testExecBackend(t)
b.Strict = func(string) bool { return false }
@@ -1402,7 +1402,7 @@ func TestAStalledStartBlocksOnlyItsHost(t *testing.T) {
func TestSwitchedOffSpawnsTakeNoNewLock(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 300 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
b := testExecBackend(t)
b.Cgroups = delegatedManager(t)
host := "off.example.com"
diff --git a/internal/activator/backend_unit_test.go b/internal/activator/backend_unit_test.go
index bb32f82b9..426bc0b3f 100644
--- a/internal/activator/backend_unit_test.go
+++ b/internal/activator/backend_unit_test.go
@@ -84,7 +84,7 @@ func testUnitActivator(t *testing.T, idle time.Duration) (*Service, *fakeBackend
if err != nil {
t.Fatalf("open registry: %v", err)
}
- a := New(Config{Bucket: "test-bucket", Idle: idle}, &SplitBackend{Exec: eb, Unit: ub}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: idle}, &SplitBackend{Exec: eb, Unit: ub}, reg)
a.now = clk.now
return a, eb, sc, clk, reg
}
@@ -203,7 +203,7 @@ func TestUnitTenantFailedHealthStopsUnit(t *testing.T) {
if err != nil {
t.Fatalf("open registry: %v", err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Minute}, &SplitBackend{Exec: &fakeBackend{}, Unit: ub}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Minute}, &SplitBackend{Exec: &fakeBackend{}, Unit: ub}, reg)
if _, err := a.beginRequest(context.Background(), route); err == nil {
t.Fatal("wake succeeded despite the health gate failing")
@@ -393,7 +393,7 @@ func TestUnitTenantWakeServesHeldRequest(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 5 * time.Second
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
eb := &fakeBackend{}
ub := &UnitBackend{Systemctl: sc.run, OptDir: t.TempDir()} // nil WaitHealthy: the real prober
@@ -402,7 +402,7 @@ func TestUnitTenantWakeServesHeldRequest(t *testing.T) {
if err != nil {
t.Fatalf("open registry: %v", err)
}
- a := New(Config{Bucket: "test-bucket", Idle: 10 * time.Second}, &SplitBackend{Exec: eb, Unit: ub}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: 10 * time.Second}, &SplitBackend{Exec: eb, Unit: ub}, reg)
a.now = clk.now
route := registry.Route{Host: "kass.example.com", Kind: "instance", Addr: addr,
diff --git a/internal/activator/binary_golden_test.go b/internal/activator/binary_golden_test.go
index 56b9eedf0..00b5bd8bb 100644
--- a/internal/activator/binary_golden_test.go
+++ b/internal/activator/binary_golden_test.go
@@ -280,7 +280,7 @@ func TestGenHealthyBoundBinary(t *testing.T) {
fmt.Fprintf(&out, "spawnHealthTimeout %s\n", spawnHealthTimeout)
oldBound, oldFloor := spawnHealthTimeout, firstWakeMinVerdict
spawnHealthTimeout, firstWakeMinVerdict = time.Second, 50*time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout, firstWakeMinVerdict = oldBound, oldFloor })
+ restoreKnob(t, func() { spawnHealthTimeout, firstWakeMinVerdict = oldBound, oldFloor })
dir, err := os.MkdirTemp("", "gh")
if err != nil {
t.Fatal(err)
diff --git a/internal/activator/canonlink_test.go b/internal/activator/canonlink_test.go
index 0149776c9..697292f9f 100644
--- a/internal/activator/canonlink_test.go
+++ b/internal/activator/canonlink_test.go
@@ -99,7 +99,7 @@ func sockGenActivator(t *testing.T, on bool) (*Service, registry.Route) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &sockGenBackend{fakeBackend: &fakeBackend{}, t: t, dir: dir}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &sockGenBackend{fakeBackend: &fakeBackend{}, t: t, dir: dir}, reg)
rt := testRoute("link.example.com")
rt.Socket = filepath.Join(dir, "c.sock")
return a, rt
diff --git a/internal/activator/claimgen_test.go b/internal/activator/claimgen_test.go
index 69a692689..181a07d79 100644
--- a/internal/activator/claimgen_test.go
+++ b/internal/activator/claimgen_test.go
@@ -112,7 +112,7 @@ func TestStartAdmittedRefusesAGenerationMismatch(t *testing.T) {
func TestClaimGenAt(t *testing.T) {
b := testExecBackend(t)
b.RunDirOverride = t.TempDir()
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
flat := registry.Route{Host: "c.example.com", Kind: "instance", DBPath: b.DataDir + "/c.example.com.db", Socket: b.RunDirOverride + "/c.example.com.sock"}
if g := a.claimGenAt(flat, 4); g.N != 4 || g.Socket != b.flatGenSocket(flat.Host, 4) || g.Control != g.Socket+".control" {
t.Fatalf("flat: %+v", g)
@@ -123,7 +123,7 @@ func TestClaimGenAt(t *testing.T) {
}
// The split backend asks its exec half; a unit-backed row has no
// generation path of its own.
- split := New(Config{}, &SplitBackend{Exec: b}, nil)
+ split := newTrackedService(Config{}, &SplitBackend{Exec: b}, nil)
if g := split.claimGenAt(flat, 6); g.N != 6 || g.Socket != b.flatGenSocket(flat.Host, 6) {
t.Fatalf("split, flat: %+v", g)
}
diff --git a/internal/activator/claimloop_linux_test.go b/internal/activator/claimloop_linux_test.go
index 88bdbebce..84280df3b 100644
--- a/internal/activator/claimloop_linux_test.go
+++ b/internal/activator/claimloop_linux_test.go
@@ -58,7 +58,7 @@ func recordClaimBackoff(t *testing.T, run *loopRun) {
fired <- time.Now()
return fired, func() bool { return false }
}
- t.Cleanup(func() { claimBackoffTimer = old })
+ restoreKnob(t, func() { claimBackoffTimer = old })
}
func (r *loopRun) starts() []time.Time {
diff --git a/internal/activator/claimrecord_linux_test.go b/internal/activator/claimrecord_linux_test.go
index 97d9be459..6507243ac 100644
--- a/internal/activator/claimrecord_linux_test.go
+++ b/internal/activator/claimrecord_linux_test.go
@@ -311,7 +311,7 @@ func claimedSidecarRestart(t *testing.T, pinned bool) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box", Bucket: "data",
+ a := newTrackedService(Config{Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box", Bucket: "data",
Read: func(context.Context, string) (hostclaim.Observed, error) {
mu.Lock()
defer mu.Unlock()
diff --git a/internal/activator/cmd_test.go b/internal/activator/cmd_test.go
index 4ed922ed5..b5220fce6 100644
--- a/internal/activator/cmd_test.go
+++ b/internal/activator/cmd_test.go
@@ -156,7 +156,7 @@ func testCmdActivator(t *testing.T, cfg Config) (*Service, *cmdFakeBackend, *fak
if cfg.Idle == 0 {
cfg.Idle = time.Second
}
- a := New(cfg, cb, reg)
+ a := newTrackedService(cfg, cb, reg)
a.now = clk.now
return a, cb, clk
}
diff --git a/internal/activator/cmdunit_test.go b/internal/activator/cmdunit_test.go
index a6529e09d..e45a2f06a 100644
--- a/internal/activator/cmdunit_test.go
+++ b/internal/activator/cmdunit_test.go
@@ -87,7 +87,7 @@ func shrinkCmdAcceptGrace(t *testing.T, d time.Duration) {
t.Helper()
old := cmdAcceptGrace
cmdAcceptGrace = d
- t.Cleanup(func() { cmdAcceptGrace = old })
+ restoreKnob(t, func() { cmdAcceptGrace = old })
}
func TestStartCmdWritesTheLaunchFileAndStartsTheUnit(t *testing.T) {
diff --git a/internal/activator/containment_test.go b/internal/activator/containment_test.go
index 2123c1153..4af850541 100644
--- a/internal/activator/containment_test.go
+++ b/internal/activator/containment_test.go
@@ -642,7 +642,7 @@ func TestASeedWhoseObligationCannotBeWrittenRunsNothing(t *testing.T) {
runs := filepath.Join(t.TempDir(), "runs")
stageSeedScript(t, b, host, "v1", fmt.Sprintf("echo run >> %q\nprintf half > \"$3\"\nexit 0\n", runs))
orig := writeSeedObligationFile
- t.Cleanup(func() { writeSeedObligationFile = orig })
+ restoreKnob(t, func() { writeSeedObligationFile = orig })
writeSeedObligationFile = func(string, []byte, os.FileMode) error { return syscall.ENOSPC }
err := b.Seed(context.Background(), registry.Route{Host: host, Kind: "instance", Seed: `["seed"]`})
diff --git a/internal/activator/demo_durability_test.go b/internal/activator/demo_durability_test.go
index 00a7ca53b..9a0d758cb 100644
--- a/internal/activator/demo_durability_test.go
+++ b/internal/activator/demo_durability_test.go
@@ -67,7 +67,7 @@ func TestDemoDatabaseSurvivesLocalRestart(t *testing.T) {
replicaGETs.Add(1)
return false, nil
}
- t.Cleanup(func() { restoreReplica = old })
+ restoreKnob(t, func() { restoreReplica = old })
fresh, err := b.Restore(ctx, rt)
if err != nil || !fresh {
t.Fatalf("new instance: fresh=%v err=%v", fresh, err)
@@ -397,7 +397,7 @@ func TestDemoDatabaseServiceSleepWakeAndAdoption(t *testing.T) {
restores.Add(1)
return false, nil
}
- t.Cleanup(func() { restoreReplica = old })
+ restoreKnob(t, func() { restoreReplica = old })
a, b, _, reg := testActivator(t, time.Hour)
t.Cleanup(func() { a.Shutdown(ctx); reg.Close() })
a.backend = &demoRestoreBackend{fakeBackend: b, disk: disk}
@@ -591,7 +591,7 @@ func TestDemoDatabaseInitializationRetry(t *testing.T) {
store := &demoInitFaultStore{Store: release.NewDirStore(t.TempDir()), fault: fault}
b.FilesStore = store
originalSync := durableSync
- t.Cleanup(func() { durableSync = originalSync })
+ restoreKnob(t, func() { durableSync = originalSync })
durableSync = func(dir string) error {
_, dbErr := os.Stat(rt.DBPath)
_, markerErr := os.Stat(rt.DBPath + AssignedMarkerSuffix)
diff --git a/internal/activator/escrow_test.go b/internal/activator/escrow_test.go
index 1b2bec2bd..41caecc41 100644
--- a/internal/activator/escrow_test.go
+++ b/internal/activator/escrow_test.go
@@ -350,7 +350,7 @@ func TestNotReadyRefusesRestoreMintAndFirstLaunch(t *testing.T) {
nb := restartEscrow(t, s.b)
s.b = nb
s.wire(nb)
- s.a = New(Config{Bucket: nb.Cfg.Bucket, Idle: time.Hour}, nb, nb.Registry)
+ s.a = newTrackedService(Config{Bucket: nb.Cfg.Bucket, Idle: time.Hour}, nb, nb.Registry)
t.Cleanup(s.abandon)
nb.EscrowKey = nil
if nb.escrowModeOf(s.rt) != escrowNoKey {
@@ -1150,7 +1150,7 @@ func TestABoxThatChangesKeyFailsClosed(t *testing.T) {
nb.FilesStore = cs
s.b = nb
s.wire(nb)
- s.a = New(Config{Bucket: nb.Cfg.Bucket, Idle: time.Hour}, nb, nb.Registry)
+ s.a = newTrackedService(Config{Bucket: nb.Cfg.Bucket, Idle: time.Hour}, nb, nb.Registry)
sealB := sealerOf(t, nb, rt)
release := holdLease(t, nb, rt)
rep := nb.EscrowSweep(ctx, []registry.Route{rt})
@@ -1274,7 +1274,7 @@ func writeFailingMarker(t *testing.T) {
t.Helper()
old := writeEscrowMarker
writeEscrowMarker = func(string, string, []byte) error { return errors.New("disk full") }
- t.Cleanup(func() { writeEscrowMarker = old })
+ restoreKnob(t, func() { writeEscrowMarker = old })
}
// P1-1 (round 2): an escrowed instance.key is write-once. A local key that
diff --git a/internal/activator/exec_gate_test.go b/internal/activator/exec_gate_test.go
index 078420ec5..63d4f69bd 100644
--- a/internal/activator/exec_gate_test.go
+++ b/internal/activator/exec_gate_test.go
@@ -311,7 +311,7 @@ func launchActivator(t *testing.T, b *launchBackend, plan WakePlan) (*Service, *
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.gens = true
evs := &genLog{}
a.OnGen = evs.add
@@ -424,7 +424,7 @@ func workerGateService(t *testing.T, flip func()) (*Service, *ExecBackend, regis
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: &fakeBackend{}, exec: eb}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: &fakeBackend{}, exec: eb}, reg)
a.GenerationsFile = release.GenerationsPath(t.TempDir())
t.Cleanup(func() { a.Shutdown(context.Background()) })
return a, eb, workerRoute(host), out, dir
diff --git a/internal/activator/generations_instances_test.go b/internal/activator/generations_instances_test.go
index 54b852740..6eaeb35b5 100644
--- a/internal/activator/generations_instances_test.go
+++ b/internal/activator/generations_instances_test.go
@@ -345,7 +345,7 @@ func claimedPlanActivator(t *testing.T, plan WakePlan) (*Service, *atomic.Int32,
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box",
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box",
Read: func(context.Context, string) (hostclaim.Observed, error) {
if reads.Add(1) == 1 {
return obs, nil
diff --git a/internal/activator/genservice_test.go b/internal/activator/genservice_test.go
index 51d678540..6d4749b67 100644
--- a/internal/activator/genservice_test.go
+++ b/internal/activator/genservice_test.go
@@ -61,7 +61,7 @@ func genActivator(t *testing.T, on bool) (*Service, *genFakeBackend) {
if err != nil {
t.Fatal(err)
}
- return New(Config{Bucket: "test-bucket", Idle: time.Hour}, gb, reg), gb
+ return newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, gb, reg), gb
}
// genTestRoute is testRoute with its canonical socket in the test's own
diff --git a/internal/activator/group_admission_test.go b/internal/activator/group_admission_test.go
index 88dc12bb9..b1a3dcdca 100644
--- a/internal/activator/group_admission_test.go
+++ b/internal/activator/group_admission_test.go
@@ -13,7 +13,7 @@ import (
func TestPreAdmissionNonHTTP(t *testing.T) {
b := &fakeBackend{}
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
a.TenantStartAllowed = func() bool { return false }
a.TenantAdmittedFunc = func() bool { return false }
rt := testRoute("shop.example.com")
@@ -65,7 +65,7 @@ func TestPreAdmissionDirectAndHop(t *testing.T) {
t.Fatal(err)
}
b := &fakeBackend{}
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
a.TenantAdmittedFunc = func() bool { return false }
a.TenantStartAllowed = func() bool { return false }
e, err := edge.New(reg, a)
@@ -126,7 +126,7 @@ func TestAdmissionLaunchRecheck(t *testing.T) {
func TestAdmissionClosesBeforeAcquire(t *testing.T) {
b := &fakeBackend{}
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
checks := 0
a.TenantStartAllowed = func() bool { checks++; return checks == 1 }
rt := testRoute("shop.example.com")
@@ -142,7 +142,7 @@ func TestAdmissionClosesBeforeAcquire(t *testing.T) {
// job for a unit bound to the edge would queue behind the drain unit's
// stop and could cancel the edge's pending stop (W6 final review F4).
func TestTenantStartsClosedRefusesExemptRoutesToo(t *testing.T) {
- a := New(Config{}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
a.TenantExempt = func(rt registry.Route) bool { return rt.Platform }
platform, tenant := registry.Route{Host: "console.example.com", Platform: true}, testRoute("shop.example.com")
if a.tenantStartRefusal(platform) != nil || a.tenantStartRefusal(tenant) != nil {
diff --git a/internal/activator/ha_pool_test.go b/internal/activator/ha_pool_test.go
index 2ad10a1a8..bdb11f9e2 100644
--- a/internal/activator/ha_pool_test.go
+++ b/internal/activator/ha_pool_test.go
@@ -16,7 +16,7 @@ import (
func TestPoolGateCannotFallBackLocal(t *testing.T) {
for _, kind := range []string{"forward", "static", "unit", "non-hibernating", "tunnel"} {
t.Run(kind, func(t *testing.T) {
- a := New(Config{}, poolDeniedBackend{}, nil)
+ a := newTrackedService(Config{}, poolDeniedBackend{}, nil)
rt := registry.Route{Host: "pass.example.com", Kind: kind, Pool: ""}
if kind == "unit" || kind == "non-hibernating" || kind == "tunnel" {
rt.Kind = "instance"
@@ -97,7 +97,7 @@ type poolDeniedBackend struct{ Backend }
func (poolDeniedBackend) poolEligible(registry.Route) bool { return false }
func TestPoolGateIndependentAdmissions(t *testing.T) {
- a := New(Config{}, poolDeniedBackend{}, nil)
+ a := newTrackedService(Config{}, poolDeniedBackend{}, nil)
rt := registry.Route{Host: "known.example.com", HA: true, Pool: "ha"}
if d := a.ForwardTarget(t.Context(), rt, nil); !d.Unavailable {
t.Fatalf("no reader: %+v", d)
diff --git a/internal/activator/haadopt_test.go b/internal/activator/haadopt_test.go
index bb012ec97..fe5a55ede 100644
--- a/internal/activator/haadopt_test.go
+++ b/internal/activator/haadopt_test.go
@@ -367,7 +367,7 @@ func TestHAAdoptRestartPhases(t *testing.T) {
defer reg.Close()
s.b.Registry = reg
sameBoxReady(s.b)
- fresh := New(s.a.cfg, s.b, reg)
+ fresh := newTrackedService(s.a.cfg, s.b, reg)
fresh.DutyStore = reg
got, err := fresh.AdoptHost(ctx, s.rt, req)
if err != nil || (got != Adopted && got != AlreadyAdopted) {
@@ -455,7 +455,7 @@ func TestHAAdoptSequentialDepartures(t *testing.T) {
t.Fatal(err)
}
s.b.Registry = reg
- s.a = New(s.a.cfg, s.b, reg)
+ s.a = newTrackedService(s.a.cfg, s.b, reg)
s.a.DutyStore = reg
req.Observed, err = lease.ReadLock(ctx, s.b.Cfg.Bucket, s.b.Cfg.hibernatePrefix(s.rt.Host), s.b.Cfg.Region)
if err != nil {
@@ -480,7 +480,7 @@ func TestHAAdoptSequentialDepartures(t *testing.T) {
return false, nil
}
s.a.now = func() time.Time { return time.Now().Add(48 * time.Hour) }
- fresh := New(s.a.cfg, s.b, s.b.Registry)
+ fresh := newTrackedService(s.a.cfg, s.b, s.b.Registry)
fresh.DutyStore = s.b.Registry
fresh.now = s.a.now
s.a = fresh
@@ -761,7 +761,7 @@ func TestHAAdoptRestartAcquiringDepartedLock(t *testing.T) {
}
defer reg.Close()
s.b.Registry = reg
- fresh := New(s.a.cfg, s.b, reg)
+ fresh := newTrackedService(s.a.cfg, s.b, reg)
fresh.DutyStore = reg
if got, err := fresh.AdoptHost(context.Background(), s.rt, req); err != nil || got != Adopted {
t.Fatalf("restart %v %v", got, err)
diff --git a/internal/activator/hadrain_test.go b/internal/activator/hadrain_test.go
index b7d172fb7..9df1466ee 100644
--- a/internal/activator/hadrain_test.go
+++ b/internal/activator/hadrain_test.go
@@ -72,7 +72,7 @@ func TestSilentDrainingHolderIsNotSuspect(t *testing.T) {
reads.Add(1)
return old(ctx, bucket, prefix, region)
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
s.a.NoteForward(s.rt.Host, edge.ForwardResult{Kind: edge.Holder, Outcome: edge.ForwardSilent, Ref: d.Ref, Gen: d.Gen, PeerGen: d.PeerGen})
if s.a.peers.snapshot(time.Now()).Suspect["b"] {
t.Fatal("silence from a draining box made it a placement suspect")
diff --git a/internal/activator/hadrainmove_test.go b/internal/activator/hadrainmove_test.go
index b44d60030..3fea75532 100644
--- a/internal/activator/hadrainmove_test.go
+++ b/internal/activator/hadrainmove_test.go
@@ -69,6 +69,16 @@ func TestDrainStopFinishFailsMarkerUnclean(t *testing.T) {
// not quiet. The activator keeps the stop.
func TestDrainStopUnprovenKeepsTheLease(t *testing.T) {
s, e := haServiceEntry(t, "shop.example.com")
+ // The stop this test leaves pending ends with the test: the unit goes,
+ // and the stop's goroutine is finished before the rig is taken down.
+ t.Cleanup(func() {
+ s.unit.set(func(u *haUnit) { u.stuck = false; u.active, u.unitPop, u.slicePop = "inactive", false, false })
+ select {
+ case <-e.stopped:
+ case <-time.After(knobJoinBound):
+ t.Errorf("the pending stop did not finish within %s of the unit going", knobJoinBound)
+ }
+ })
s.unit.set(func(u *haUnit) { u.stuck, u.slicePop = true, false })
before := len(s.lockWriteLog())
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
diff --git a/internal/activator/haescrow_branchfix_test.go b/internal/activator/haescrow_branchfix_test.go
index f1adc13c6..fc9580c89 100644
--- a/internal/activator/haescrow_branchfix_test.go
+++ b/internal/activator/haescrow_branchfix_test.go
@@ -236,7 +236,7 @@ func TestHASnapshotRefreshRestagesWholeTree(t *testing.T) {
t.Fatal(err)
}
previous := syncFilesAt
- t.Cleanup(func() { syncFilesAt = previous })
+ restoreKnob(t, func() { syncFilesAt = previous })
first := true
syncFilesAt = func(ctx context.Context, p *hostfiles.Publisher, dir *os.File, skip func(string, bool) bool) (hostfiles.SyncStats, error) {
if !first {
diff --git a/internal/activator/hafiles_test.go b/internal/activator/hafiles_test.go
index a97d4a521..1af16c775 100644
--- a/internal/activator/hafiles_test.go
+++ b/internal/activator/hafiles_test.go
@@ -242,7 +242,7 @@ func TestIncompleteSnapshotRunsAgainOverAnUnchangedTree(t *testing.T) {
}
return prev(ctx, p, dir, skip)
}
- t.Cleanup(func() { syncFilesAt = prev })
+ restoreKnob(t, func() { syncFilesAt = prev })
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go f.Run(ctx)
@@ -276,7 +276,7 @@ func TestPlatformPublishesDuringASnapshot(t *testing.T) {
}
return prev(ctx, p, dir, skip)
}
- t.Cleanup(func() { syncFilesAt = prev })
+ restoreKnob(t, func() { syncFilesAt = prev })
ctx, cancel := context.WithCancel(context.Background())
ran := make(chan struct{})
go func() { defer close(ran); f.Run(ctx) }()
diff --git a/internal/activator/haforward_test.go b/internal/activator/haforward_test.go
index 96334bb6f..0d9cc52e1 100644
--- a/internal/activator/haforward_test.go
+++ b/internal/activator/haforward_test.go
@@ -24,7 +24,7 @@ func asForwarded(t *testing.T) {
t.Helper()
old := forwardedHop
forwardedHop = func(*http.Request) bool { return true }
- t.Cleanup(func() { forwardedHop = old })
+ restoreKnob(t, func() { forwardedHop = old })
}
// lockGets counts the GETs of rt's lock.json.
@@ -143,7 +143,7 @@ func TestForwardTargetSingleFlight(t *testing.T) {
<-gate
return old(ctx, bucket, prefix, region)
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
got := s.concurrently(20)
waitFor(t, "the first read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the other 19 queue on it
@@ -286,7 +286,7 @@ func TestHoppedOtherRefusalsSayNone(t *testing.T) {
asForwarded(t)
old := wakeWaitBound
wakeWaitBound = 100 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
cases := []struct {
name string
retry string
@@ -370,7 +370,7 @@ func TestScheduledTickNeverForwards(t *testing.T) {
reads.Add(1)
return old(ctx, bucket, prefix, region)
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
rec := httptest.NewRecorder()
s.a.ServeScheduled(rec, httptest.NewRequest("POST", "http://shop.example.com/", nil), s.rt, mustNotProxy(t))
if rec.Code != 503 || rec.Header().Get("Retry-After") == "" || rec.Header().Get("Retry-After") == "1" ||
@@ -393,7 +393,7 @@ func TestScheduledTickNeverForwards(t *testing.T) {
// unit-backed row, which cannot be born HA here, reads nothing.
func TestForwardTargetThroughSplitBackend(t *testing.T) {
s := haHeldByB(t)
- a := New(Config{Bucket: s.b.Cfg.Bucket, Idle: time.Hour}, &SplitBackend{Exec: s.b, Unit: &UnitBackend{}}, s.b.Registry)
+ a := newTrackedService(Config{Bucket: s.b.Cfg.Bucket, Idle: time.Hour}, &SplitBackend{Exec: s.b, Unit: &UnitBackend{}}, s.b.Registry)
d := a.ForwardTarget(context.Background(), s.rt, nil)
if d.Ref != "b" {
t.Fatalf("ForwardTarget through the split backend = %+v, want b", d)
diff --git a/internal/activator/haleaseloss_test.go b/internal/activator/haleaseloss_test.go
index a5727d5f5..e43ae3871 100644
--- a/internal/activator/haleaseloss_test.go
+++ b/internal/activator/haleaseloss_test.go
@@ -373,7 +373,7 @@ func TestHALostLeaseRecoveryAttemptAndShutdown(t *testing.T) {
<-ctx.Done()
return hafresh.View{}, ctx.Err()
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
s.a.retryHALostHost(s.rt)
<-entered
for i := 0; i < 20; i++ {
@@ -443,7 +443,7 @@ func TestHALostLeaseRecoveryAcquireBudget(t *testing.T) {
<-ctx.Done()
return nil, ctx.Err()
}
- t.Cleanup(func() { acquireHALease = old })
+ restoreKnob(t, func() { acquireHALease = old })
s.a.retryHALostHost(s.rt)
s.a.haLoss.joined.Wait()
if !called {
@@ -461,7 +461,7 @@ func (lostDiscoveryBackend) readHolderView(ctx context.Context, _ registry.Route
}
func TestHALostLeaseRecoveryWorkersBounded(t *testing.T) {
- a := New(Config{}, lostDiscoveryBackend{}, nil)
+ a := newTrackedService(Config{}, lostDiscoveryBackend{}, nil)
a.haLoss.hosts = make(map[string]*haLeaseLoss)
a.Routes = withdrawalLookup(func(host string) (*registry.Route, error) {
return &registry.Route{Host: host, HA: true, Kind: "instance"}, nil
@@ -644,7 +644,7 @@ func (b *lostCountingBackend) readHolderView(context.Context, registry.Route) (h
func TestHALostRecoveryMassLossAndDemandExpiry(t *testing.T) {
b := &lostCountingBackend{fakeBackend: &fakeBackend{}}
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
defer a.lifeStop()
clk := &fakeClock{t: time.Now()}
a.now = clk.now
diff --git a/internal/activator/handover_test.go b/internal/activator/handover_test.go
index 114b48ff3..48826640e 100644
--- a/internal/activator/handover_test.go
+++ b/internal/activator/handover_test.go
@@ -32,7 +32,7 @@ func shortMoveBounds(t *testing.T, client, hop time.Duration) {
t.Helper()
oc, oh := moveHoldClient, moveHoldHop
moveHoldClient, moveHoldHop = client, hop
- t.Cleanup(func() { moveHoldClient, moveHoldHop = oc, oh })
+ restoreKnob(t, func() { moveHoldClient, moveHoldHop = oc, oh })
}
// waitAsync runs d.Wait in the background.
diff --git a/internal/activator/haplacement_test.go b/internal/activator/haplacement_test.go
index 74667e604..fbb5b94fa 100644
--- a/internal/activator/haplacement_test.go
+++ b/internal/activator/haplacement_test.go
@@ -205,7 +205,7 @@ func TestPlacementSnapshotIsLazy(t *testing.T) {
readHolderLock = func(context.Context, string, string, string) (hafresh.View, error) {
return hafresh.View{}, context.DeadlineExceeded
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
}
case "awake":
s.a.entries[s.rt.Host] = &actEntry{route: s.rt, state: actAwake, proc: &fakeProc{}, rep: &fakeRep{}}
@@ -240,7 +240,7 @@ func TestPlacementSingleFlight(t *testing.T) {
<-gate
return old(ctx, b, p, r)
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
ctx, cancel := context.WithCancel(context.Background())
first := make(chan edge.ForwardDecision, 1)
go func() { first <- s.a.ForwardTarget(ctx, s.rt, nil) }()
@@ -274,7 +274,7 @@ func TestPlacementProbeFailureUsesBase(t *testing.T) {
readHolderLock = func(context.Context, string, string, string) (hafresh.View, error) {
return hafresh.View{}, errors.New("unavailable")
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
if d := s.a.ForwardTarget(context.Background(), s.rt, func() boxchoice.WakeSnapshot { return placementSnapshot(time.Now()) }); d != (edge.ForwardDecision{}) {
t.Fatal(d)
}
diff --git a/internal/activator/harelease_test.go b/internal/activator/harelease_test.go
index 87e95ea4d..b173501fc 100644
--- a/internal/activator/harelease_test.go
+++ b/internal/activator/harelease_test.go
@@ -192,7 +192,7 @@ func haService(t *testing.T, host string) *haSvc {
h.mu.Unlock()
}
})
- s.a = New(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
+ s.a = newTrackedService(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
t.Cleanup(s.abandon)
return s
}
@@ -314,7 +314,7 @@ func (s *haSvc) peer(t *testing.T) *haSvc {
t.Cleanup(func() { haFixtures.Delete(b) })
s2 := &haSvc{t: t, b: b, rt: s.rt, fx: s.fx, ctl: s.ctl, unit: s.unit, owedDir: s.owedDir}
s2.wire(b)
- s2.a = New(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
+ s2.a = newTrackedService(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
t.Cleanup(s2.abandon)
return s2
}
@@ -760,7 +760,7 @@ func TestSweepRetriesOwedMarkers(t *testing.T) {
release := make(chan struct{})
prev := retryPendingMarkers
retryPendingMarkers = func(context.Context) error { calls.Add(1); <-release; return nil }
- t.Cleanup(func() { retryPendingMarkers = prev })
+ restoreKnob(t, func() { retryPendingMarkers = prev })
s.a.sweepOnce()
s.a.sweepOnce() // the first is still running: no second pass
waitFor(t, "the retry", func() bool { return calls.Load() == 1 })
diff --git a/internal/activator/hasecrets_test.go b/internal/activator/hasecrets_test.go
index c06c65808..ecd1f244e 100644
--- a/internal/activator/hasecrets_test.go
+++ b/internal/activator/hasecrets_test.go
@@ -296,7 +296,7 @@ func TestLegacyLaunchPublishesNothing(t *testing.T) {
// host's tick is left alone.
func TestFillScheduledToken(t *testing.T) {
b, rt := haLaunchBackend(t, "shop.example.com")
- a := New(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
+ a := newTrackedService(Config{Bucket: b.Cfg.Bucket, Idle: time.Hour}, b, b.Registry)
writeEnv(t, b, rt, "CARLOS_ADMIN_TOKEN=restored\n")
r := httptest.NewRequest(http.MethodPost, "http://shop.example.com/tick", nil)
r.Header.Set("Authorization", "Bearer ")
diff --git a/internal/activator/hasuspect_test.go b/internal/activator/hasuspect_test.go
index 3c4df52e3..7f5eba7d0 100644
--- a/internal/activator/hasuspect_test.go
+++ b/internal/activator/hasuspect_test.go
@@ -158,7 +158,7 @@ func TestSuspectWindowEndReadsOnce(t *testing.T) {
<-gate
return old(ctx, bucket, prefix, region)
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
got := s.concurrently(20)
waitFor(t, "the read", func() bool { return reads.Load() == 1 })
time.Sleep(50 * time.Millisecond) // the others queue on it
@@ -224,7 +224,7 @@ func TestSuspectRevalidationFailureRenewsTheWindow(t *testing.T) {
<-ctx.Done()
return hafresh.View{}, ctx.Err()
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
got := s.concurrently(5)
for i := range 5 {
if d := recv(t, got); !d.Refuse {
@@ -246,7 +246,7 @@ func TestSuspectRevalidationFailureRenewsTheWindow(t *testing.T) {
<-gate
return hafresh.View{}, context.DeadlineExceeded
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
got := s.concurrently(1)
waitFor(t, "the read", func() bool { return reads.Load() == 1 })
s.a.NoteForward(s.rt.Host, edge.ForwardResult{Outcome: edge.ForwardDone, Ref: "c", Status: 503, Holder: "c"})
@@ -272,7 +272,7 @@ func TestSuccessDuringRevalidationWins(t *testing.T) {
<-gate
return hafresh.View{}, context.DeadlineExceeded
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
return func() bool { return reads.Load() == 1 }, func() { close(gate) }
}
t.Run("success", func(t *testing.T) {
@@ -617,7 +617,7 @@ func TestSuspectWindowRevalidationTimeout(t *testing.T) {
<-ctx.Done()
return hafresh.View{}, ctx.Err()
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
first := make(chan edge.ForwardDecision, 1)
@@ -707,7 +707,7 @@ func TestSilentHolderRevalidatesOnce(t *testing.T) {
return old(ctx, bucket, prefix, region)
}
}
- t.Cleanup(func() { readHolderLock = old })
+ restoreKnob(t, func() { readHolderLock = old })
out := s.concurrently(50)
free := answer == "absent" || answer == "released"
for range 50 {
diff --git a/internal/activator/hatake_test.go b/internal/activator/hatake_test.go
index 15dfbfa79..008ebd4b2 100644
--- a/internal/activator/hatake_test.go
+++ b/internal/activator/hatake_test.go
@@ -338,7 +338,7 @@ func TestTakeWithinTheWakeBound(t *testing.T) {
putLockFor(t, s.b, s.rt, takeMarker(t, s.lifetime(), 6))
old := wakeWaitBound
wakeWaitBound = 200 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
// The take's wake runs on, detached, after the take answers, holding
// the lease it acquired; ended, it gives the lease back (a release
// marker). It must end inside this test. Left running, it wrote that
@@ -482,11 +482,11 @@ func TestTakeBoundOnAFirstWake(t *testing.T) {
}
old := wakeWaitBound
wakeWaitBound = 200 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
extendedCh := make(chan struct{}, 4)
oldHook := wakeBoundExtended
wakeBoundExtended = func() { extendedCh <- struct{}{} }
- t.Cleanup(func() { wakeBoundExtended = oldHook })
+ restoreKnob(t, func() { wakeBoundExtended = oldHook })
// A first wake under way: never ready until the test ends it.
var e *actEntry
s.a.mu.Lock()
diff --git a/internal/activator/hawake_test.go b/internal/activator/hawake_test.go
index 9e8d6b01e..080eb6a1c 100644
--- a/internal/activator/hawake_test.go
+++ b/internal/activator/hawake_test.go
@@ -150,7 +150,7 @@ func haBackendEmptyIndex(t *testing.T, host string) (*ExecBackend, registry.Rout
}
return true, writeMinimalSQLite(dbPath)
}
- t.Cleanup(func() { restoreReplica = old })
+ restoreKnob(t, func() { restoreReplica = old })
haFixtures.Store(b, h)
t.Cleanup(func() { haFixtures.Delete(b) })
return b, rt
@@ -1157,7 +1157,7 @@ func TestWakeReplicatesAtTheRestoredClass(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Minute}, &restoredClassBackend{fakeBackend: fb, class: replicationStream}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Minute}, &restoredClassBackend{fakeBackend: fb, class: replicationStream}, reg)
rt := testRoute("shop.example.com")
rt.Replication = replicationDaily
release, err := a.beginRequest(context.Background(), rt)
diff --git a/internal/activator/heldstream_e2e_test.go b/internal/activator/heldstream_e2e_test.go
index 5613f12a5..7cfb9e1fa 100644
--- a/internal/activator/heldstream_e2e_test.go
+++ b/internal/activator/heldstream_e2e_test.go
@@ -141,7 +141,7 @@ func newHeldE2E(t *testing.T, o heldE2EOpts) *heldE2E {
t.Fatal(err)
}
be := &heldE2EBackend{fakeSwapBackend: &fakeSwapBackend{fakeBackend: &fakeBackend{}}, exec: exec}
- h.a = New(Config{Bucket: "test-bucket", Idle: o.idle}, be, reg)
+ h.a = newTrackedService(Config{Bucket: "test-bucket", Idle: o.idle}, be, reg)
h.a.gens = o.gens
t.Cleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
diff --git a/internal/activator/instancekey_test.go b/internal/activator/instancekey_test.go
index dd515c94f..e3604b86c 100644
--- a/internal/activator/instancekey_test.go
+++ b/internal/activator/instancekey_test.go
@@ -839,7 +839,7 @@ func TestHibernationRestoreKeepsTheInstanceKey(t *testing.T) {
restoreReplica = func(_ context.Context, dbPath, bucket, prefix, region string) (bool, error) {
return true, writeMinimalSQLite(dbPath)
}
- t.Cleanup(func() { restoreReplica = old })
+ restoreKnob(t, func() { restoreReplica = old })
_ = os.Remove(filepath.Join(b.DataDir, host+".db")) // hibernated: the database is gone
rt := registry.Route{Host: host, Kind: "instance", Socket: tmpSock(t)}
if fresh, err := b.Restore(context.Background(), rt); err != nil || fresh {
diff --git a/internal/activator/knobrestore_test.go b/internal/activator/knobrestore_test.go
new file mode 100644
index 000000000..832031e97
--- /dev/null
+++ b/internal/activator/knobrestore_test.go
@@ -0,0 +1,216 @@
+package activator
+
+import (
+ "runtime"
+ "slices"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+)
+
+// knobJoinBound is how long a test's end waits for the production goroutines
+// it started. Like waitBackground's bound, it is only reached by a leak.
+const knobJoinBound = 10 * time.Second
+
+// knobRestores holds each running test's restores until the test ends.
+var knobRestores = struct {
+ sync.Mutex
+ byTest map[*testing.T][]func()
+ // abandoned names goroutines a test already reported as never ending,
+ // so that one leak fails one test and not every test after it.
+ abandoned map[string]bool
+ // services are the Services built since the last top-level test ended.
+ services []*Service
+}{byTest: map[*testing.T][]func(){}, abandoned: map[string]bool{}}
+
+// newTrackedService is New for tests: the join at a test's end synchronises
+// with every Service built this way (syncWithServices).
+func newTrackedService(cfg Config, backend Backend, due DueStore) *Service {
+ a := New(cfg, backend, due)
+ knobRestores.Lock()
+ defer knobRestores.Unlock()
+ knobRestores.services = append(knobRestores.services, a)
+ return a
+}
+
+// restoreKnob puts a package-level setting back when t ends, once the
+// production goroutines t started have finished. A wake outlives the request
+// that began it, so restoring a timing knob in a plain t.Cleanup writes the
+// variable while that wake may still read it: a data race under -race, though
+// production never changes these knobs (#1249).
+//
+// Every restore of a test runs together, last first, at the point of the
+// test's first restoreKnob. Cleanups registered after that point run before
+// the join, so a rig's cleanup can release a wake the join then waits for.
+// Shrink a knob before building the rig whose cleanup ends the wake.
+func restoreKnob(t *testing.T, restore func()) {
+ t.Helper()
+ knobRestores.Lock()
+ defer knobRestores.Unlock()
+ if _, ok := knobRestores.byTest[t]; !ok {
+ t.Cleanup(func() { runKnobRestores(t) })
+ }
+ knobRestores.byTest[t] = append(knobRestores.byTest[t], restore)
+}
+
+func runKnobRestores(t *testing.T) {
+ t.Helper()
+ joinProductionGoroutines(t)
+ syncWithServices(t)
+ knobRestores.Lock()
+ restores := knobRestores.byTest[t]
+ delete(knobRestores.byTest, t)
+ knobRestores.Unlock()
+ for i := len(restores) - 1; i >= 0; i-- {
+ restores[i]()
+ }
+}
+
+// joinProductionGoroutines waits until no goroutine is running this package's
+// production code, apart from the idle ones idleGoroutineRoots names. It polls
+// because production has no signal for "every goroutine has ended", and the
+// goroutines that matter are not all counted in Service.background: the
+// first-wake watch (watchFirstWake) is one that is not.
+func joinProductionGoroutines(t *testing.T) {
+ t.Helper()
+ live := productionGoroutines()
+ if len(live) == 0 {
+ return
+ }
+ deadline := time.After(knobJoinBound)
+ tick := time.NewTicker(time.Millisecond)
+ defer tick.Stop()
+ for len(live) > 0 {
+ select {
+ case <-tick.C:
+ live = productionGoroutines()
+ case <-deadline:
+ knobRestores.Lock()
+ for _, g := range live {
+ knobRestores.abandoned[goroutineHeader(g)] = true
+ }
+ knobRestores.Unlock()
+ t.Errorf("%d production goroutines still running %s after the test ended:\n%s",
+ len(live), knobJoinBound, strings.Join(live, "\n\n"))
+ return
+ }
+ }
+}
+
+// syncWithServices orders everything the finished goroutines did before the
+// restores that follow. Seeing a goroutine gone from the stacks shows that it
+// ended, but the race detector only believes a synchronisation: without one
+// it still reports the goroutine's last read against the restore. A wake's
+// last act is its Service.background decrement, and the other goroutines
+// finish their knob reads before a last critical section under a.mu, so
+// loading the one and taking the other is that synchronisation.
+func syncWithServices(t *testing.T) {
+ t.Helper()
+ knobRestores.Lock()
+ services := slices.Clone(knobRestores.services)
+ if !strings.Contains(t.Name(), "/") {
+ knobRestores.services = nil
+ }
+ knobRestores.Unlock()
+ deadline := time.After(knobJoinBound)
+ tick := time.NewTicker(time.Millisecond)
+ defer tick.Stop()
+ for _, a := range services {
+ a.background.Load()
+ for !a.mu.TryLock() {
+ select {
+ case <-tick.C:
+ case <-deadline:
+ t.Errorf("a Service's lock was still held %s after the test ended", knobJoinBound)
+ return
+ }
+ }
+ a.mu.Unlock()
+ }
+}
+
+// idleGoroutineRoots are goroutines that outlive their tests by design and
+// read no knob a test restores: each is parked on a listener, a unit or a
+// lease until its owner goes, and takes its timings from fields or arguments.
+var idleGoroutineRoots = []string{
+ "activator.(*logListener).accept(",
+ "activator.(*logListener).tee(",
+ "activator.(*ExecBackend).observe(",
+ "activator.(*ExecBackend).retryStrictCleanup(",
+ "activator.(*unitProc).Stop.func1(",
+ "activator.(*Service).watchResidentLease(",
+ "activator.(*Service).superviseRelease(",
+}
+
+// productionGoroutines returns the stacks of the other goroutines that are
+// running this package's production code and are worth waiting for.
+func productionGoroutines() []string {
+ buf := make([]byte, 1<<20)
+ for {
+ n := runtime.Stack(buf, true)
+ if n < len(buf) {
+ buf = buf[:n]
+ break
+ }
+ buf = make([]byte, 2*len(buf))
+ }
+ knobRestores.Lock()
+ defer knobRestores.Unlock()
+ var live []string
+ // The first stack is this goroutine's own.
+ for _, g := range strings.Split(string(buf), "\n\n")[1:] {
+ if runsProductionCode(g) && !isIdleGoroutine(g) && !knobRestores.abandoned[goroutineHeader(g)] {
+ live = append(live, g)
+ }
+ }
+ return live
+}
+
+// goroutineHeader is a stack's goroutine number, without the state that
+// changes as it runs ("goroutine 12 [select]:" gives "goroutine 12").
+func goroutineHeader(g string) string {
+ header, _, _ := strings.Cut(g, " [")
+ return header
+}
+
+// stackFrames returns a stack's frames as function and file lines, without
+// its header or the "created by" lines that name the goroutine's parent.
+func stackFrames(g string) []string {
+ lines := strings.Split(g, "\n")[1:]
+ for i, line := range lines {
+ if strings.HasPrefix(line, "created by ") {
+ return lines[:i]
+ }
+ }
+ return lines
+}
+
+func runsProductionCode(g string) bool {
+ for _, line := range stackFrames(g) {
+ if !strings.HasPrefix(line, "\t") {
+ continue
+ }
+ file, _, _ := strings.Cut(strings.TrimSpace(line), ":")
+ if strings.Contains(file, "internal/activator/") && !strings.HasSuffix(file, "_test.go") {
+ return true
+ }
+ }
+ return false
+}
+
+// isIdleGoroutine reports whether g's outermost function is an idle root.
+func isIdleGoroutine(g string) bool {
+ root := ""
+ for _, line := range stackFrames(g) {
+ if line != "" && !strings.HasPrefix(line, "\t") {
+ root = line
+ }
+ }
+ for _, idle := range idleGoroutineRoots {
+ if strings.Contains(root, idle) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/internal/activator/maintenance_test.go b/internal/activator/maintenance_test.go
index d4a526228..96d191565 100644
--- a/internal/activator/maintenance_test.go
+++ b/internal/activator/maintenance_test.go
@@ -171,7 +171,7 @@ func TestMaintenanceFenceBlocksEveryAdmissionIncludingStaleRoute(t *testing.T) {
t.Fatal("older generation accepted")
}
// A new process has no closure evidence from the old activator's lifetime.
- fresh := New(a.cfg, a.backend, reg)
+ fresh := newTrackedService(a.cfg, a.backend, reg)
if proof, err := fresh.FenceAndStop(maintenanceContext(t, time.Second), host, 3); err != ErrStopUnproven || proof != nil {
t.Fatal("restart invented old evidence")
}
diff --git a/internal/activator/opset_test.go b/internal/activator/opset_test.go
index 4d70cec2b..b687ca043 100644
--- a/internal/activator/opset_test.go
+++ b/internal/activator/opset_test.go
@@ -168,7 +168,7 @@ func TestBarrierKeepsTheLeaseWhileAGenerationIsUnproven(t *testing.T) {
x := awakeForBarrier(t, true)
old := opJoinBound
opJoinBound = 100 * time.Millisecond
- t.Cleanup(func() { opJoinBound = old })
+ restoreKnob(t, func() { opJoinBound = old })
member := &fakeProc{label: "gen:9", rec: x.b, stuck: true}
plantMember(t, x.a, x.host, roleRetiring, member, 9)
waitFor(t, "the member marked unproven", func() bool {
@@ -246,7 +246,7 @@ func TestSwapWitnessMemberStopProvesTheGenerationChildEmpty(t *testing.T) {
x := awakeForBarrier(t, true)
old := opJoinBound
opJoinBound = 100 * time.Millisecond
- t.Cleanup(func() { opJoinBound = old })
+ restoreKnob(t, func() { opJoinBound = old })
kb := &killGenBackend{fakeBackend: x.b, err: errors.New("g9 still holds a process")}
x.a.backend = kb
member := &fakeProc{label: "gen:9", rec: x.b} // its leader exits on SIGTERM
@@ -688,7 +688,7 @@ func (g *execGenBackend) firstGen() uint64 {
func TestAPlacedSpawnWithAFailedHealthWaitProvesItsChild(t *testing.T) {
old := spawnHealthTimeout
spawnHealthTimeout = 300 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
rows := []struct {
name string
containment bool
@@ -1342,7 +1342,7 @@ func TestARealFlatHealthFailedWakeProvesItsHostCgroup(t *testing.T) {
requireUnixSockets(t)
old := spawnHealthTimeout
spawnHealthTimeout = 500 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
a, b, _, _ := testActivator(t, time.Hour)
a.gens = false
exec := testExecBackend(t)
diff --git a/internal/activator/outcome_fence_test.go b/internal/activator/outcome_fence_test.go
index 582479c85..c48ead63a 100644
--- a/internal/activator/outcome_fence_test.go
+++ b/internal/activator/outcome_fence_test.go
@@ -132,7 +132,7 @@ func TestANewWakeWaitsForAFailedFirstWakesOutcome(t *testing.T) {
func TestTheOutcomeFenceFailsClosed(t *testing.T) {
old := outcomeFenceWait
outcomeFenceWait = 200 * time.Millisecond
- t.Cleanup(func() { outcomeFenceWait = old })
+ restoreKnob(t, func() { outcomeFenceWait = old })
dir := t.TempDir()
next := stagedID(t, dir, "v2")
a, b, _ := planActivator(t, WakePlan{})
diff --git a/internal/activator/pendingwake_linux_test.go b/internal/activator/pendingwake_linux_test.go
index e3f9b0517..728735058 100644
--- a/internal/activator/pendingwake_linux_test.go
+++ b/internal/activator/pendingwake_linux_test.go
@@ -204,7 +204,7 @@ func fleetBox(t *testing.T, name string, lock *sharedLock, bucket *fleetBucket,
}
box := &leasedBox{ruleBackend: &ruleBackend{fakeBackend: &fakeBackend{}, eb: eb, t: t},
t: t, name: name, lock: lock, bucket: bucket, dbPath: rt.DBPath}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, box, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, box, reg)
a.Routes = reg
return a, box, reg
}
@@ -979,7 +979,7 @@ func TestFenceHoldsAfterAgentRestartBeforeReconcile(t *testing.T) {
r.bucket.upload(t, newer)
moveRecord(t, store, "", "pi-2", assignB)
- restarted := New(Config{Bucket: "test-bucket", Idle: time.Hour}, r.box, r.reg)
+ restarted := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, r.box, r.reg)
restarted.Routes = r.reg
asFleetBox(restarted, "pi-1", store)
t.Cleanup(func() { restarted.Shutdown(context.Background()) })
@@ -1443,7 +1443,7 @@ func newCheckpointRig(t *testing.T, region string) *checkpointRig {
t.Fatal(err)
}
r := &checkpointRig{fx: fx, b: b, rt: rt, prefix: b.Cfg.hibernatePrefix(rt.Host), log: captureLog(t), kept: make(chan string, 8)}
- r.a = New(Config{Bucket: fx.Bucket, Idle: time.Hour}, b, reg)
+ r.a = newTrackedService(Config{Bucket: fx.Bucket, Idle: time.Hour}, b, reg)
r.a.checkpointKept = func(host string) { r.kept <- host }
// Whatever a test leaves running stops before the fixture closes,
// unless the test shut the agent down itself.
diff --git a/internal/activator/probewake_test.go b/internal/activator/probewake_test.go
index 54d02170f..1706f35d1 100644
--- a/internal/activator/probewake_test.go
+++ b/internal/activator/probewake_test.go
@@ -113,7 +113,7 @@ func pwFlip() hostclaim.Observed {
func pwService(t *testing.T, r *pwRuntime) (*Service, *pwRoutes) {
t.Helper()
routes := &pwRoutes{rt: registry.Route{Host: pwHost, Kind: "instance", Status: "landing", HoldOp: pwOp, Socket: "/run/x.sock", DBPath: "/data/x.db"}}
- a := New(Config{HostWrites: hostwrite.Config{Enabled: true}, Claims: r.runtime(t)}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{HostWrites: hostwrite.Config{Enabled: true}, Claims: r.runtime(t)}, &fakeBackend{}, nil)
a.Routes = routes
return a, routes
}
@@ -359,7 +359,7 @@ func TestRetireExceptKeepsAProbeInsertedBetweenTheLocks(t *testing.T) {
a.entries[inserted.host] = inserted
a.mu.Unlock()
}
- t.Cleanup(func() { retireBetweenLocks = nil })
+ restoreKnob(t, func() { retireBetweenLocks = nil })
a.RetireExcept(map[string]bool{})
retireBetweenLocks = nil
a.mu.Lock()
@@ -390,7 +390,7 @@ func TestProbeWakeCancelBeforeTheWakeStarts(t *testing.T) {
}
ctx, cancel := context.WithCancel(t.Context())
probeWakePublished = cancel
- t.Cleanup(func() { probeWakePublished = nil })
+ restoreKnob(t, func() { probeWakePublished = nil })
_, err := a.ProbeWake(ctx, pwConfig())
if !errors.Is(err, context.Canceled) {
t.Fatalf("err = %v", err)
@@ -556,7 +556,7 @@ func TestRetireExceptRevalidatesTheOpenUnderTheFinalLock(t *testing.T) {
t.Errorf("release: %v %v", ok, err)
}
}
- t.Cleanup(func() { retireBeforeRegistryRead = nil })
+ restoreKnob(t, func() { retireBeforeRegistryRead = nil })
a.RetireExcept(map[string]bool{})
retireBeforeRegistryRead = nil
a.mu.Lock()
@@ -593,7 +593,7 @@ func TestRetireExceptOverlappingReloadsAcrossTheOpen(t *testing.T) {
a.ConfirmProbeOpened("one.example.com", pwOp)
a.RetireExcept(map[string]bool{"one.example.com": true})
}
- t.Cleanup(func() { retireBeforeRegistryRead = nil })
+ restoreKnob(t, func() { retireBeforeRegistryRead = nil })
a.RetireExcept(map[string]bool{})
a.mu.Lock()
state := e.state
diff --git a/internal/activator/production_backend_test.go b/internal/activator/production_backend_test.go
index 487fffe04..e0e4e28a8 100644
--- a/internal/activator/production_backend_test.go
+++ b/internal/activator/production_backend_test.go
@@ -158,7 +158,7 @@ func TestRootfsGatesThroughTheProductionBackend(t *testing.T) {
eb, ctl := newRootfsBackend(t)
eb.RootfsOK = func(context.Context) error { return errors.New("root-image fail") }
cb := &countingSplit{SplitBackend: productionBackend(t, eb)}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, cb, nil)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, cb, nil)
a.gens = true
armRootfsForTest(a)
t.Cleanup(func() { a.Shutdown(context.Background()) })
diff --git a/internal/activator/pty_linux_test.go b/internal/activator/pty_linux_test.go
index 8b43eaaf6..4b6b428e6 100644
--- a/internal/activator/pty_linux_test.go
+++ b/internal/activator/pty_linux_test.go
@@ -607,7 +607,7 @@ func TestTTYUnitPollsAndStopsItsOwnRole(t *testing.T) {
func TestTTYUnitStopAndSettleClosesTheMaster(t *testing.T) {
old := roleEmptyBound
roleEmptyBound = 100 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
b, rt, _, unit, u := startBinaryTTY(t)
term := u.Terminal()
sock := b.logSocketNamed(rt.Host, TTYSocketName)
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go
index eadee464c..b24871682 100644
--- a/internal/activator/replica_drill1_test.go
+++ b/internal/activator/replica_drill1_test.go
@@ -32,7 +32,7 @@ import (
func TestReplicaCopyKeepsServingWhenCopiesRaised(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
r := newWakeRelRig(t)
store := wireStatelessRig(r)
r.rt.Region, r.rt.Hibernate, r.rt.Stateless = "fleet/pi", false, true
@@ -603,7 +603,7 @@ func TestReplicaKeptFenceHeldUntilAck(t *testing.T) {
func TestJoinConfigWaitKeepsStepOpen(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
join := func(inc string) *replicas.Deploy {
return &replicas.Deploy{ID: "deploy-v2", Incarnation: inc, Target: replicaTarget, BaselineSet: true, LastGood: replicaTarget, Phase: "released", Term: "term", Revision: 5,
Swap: replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}}
diff --git a/internal/activator/replica_install_wait_test.go b/internal/activator/replica_install_wait_test.go
index 01103dbfb..78030c71d 100644
--- a/internal/activator/replica_install_wait_test.go
+++ b/internal/activator/replica_install_wait_test.go
@@ -49,7 +49,7 @@ func newInstallRigIn(t *testing.T, state func(string) *replicas.Deploy) *install
t.Helper()
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
r := newReplicaSetRig(t, "b", state)
r.rt.Hibernate = false
r.routes.set(r.rt)
diff --git a/internal/activator/replicadeploy_test.go b/internal/activator/replicadeploy_test.go
index 6cb4335d3..9c95355f5 100644
--- a/internal/activator/replicadeploy_test.go
+++ b/internal/activator/replicadeploy_test.go
@@ -315,7 +315,7 @@ func TestReplicaReturnsAfterDeploy(t *testing.T) {
func TestReplicaSwapAcksOnlyAfterProof(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
permitted := replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5})
ctx := context.Background()
@@ -465,7 +465,7 @@ func TestReplicaReturnsAfterDeployWithStaleInstall(t *testing.T) {
func TestReplicaSwapProofOnlySteps(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
ctx := context.Background()
permit := replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}
halted := permit
@@ -553,7 +553,7 @@ func TestReplicaSwapProofOnlySteps(t *testing.T) {
func TestReplicaSwapWaitsForWorkers(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
ctx := context.Background()
// A worker that never starts is judged against its start bound
// (TestReplicaSwapWorkerProofTiming, fix round 3).
@@ -623,7 +623,7 @@ func TestReplicaWakeAndAdoptLaggingPointer(t *testing.T) {
func TestReplicaSwapRetiresAfterRoutedRequests(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
r.awake(t)
old, _ := r.a.Current(r.rt.Host)
@@ -682,7 +682,7 @@ func TestReplicaSwapRetiresAfterRoutedRequests(t *testing.T) {
func TestReplicaSwapWorkerProofTiming(t *testing.T) {
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
ctx := context.Background()
setup := func(t *testing.T) (*replicaSetRig, *fakeWorkerBackend) {
r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
diff --git a/internal/activator/replicaswitchfail_test.go b/internal/activator/replicaswitchfail_test.go
index 15994e16b..cef477a76 100644
--- a/internal/activator/replicaswitchfail_test.go
+++ b/internal/activator/replicaswitchfail_test.go
@@ -18,7 +18,7 @@ func switchedRig(t *testing.T) (*replicaSetRig, func() SwapResult) {
t.Helper()
prev := swapSettle
swapSettle = 20 * time.Millisecond
- t.Cleanup(func() { swapSettle = prev })
+ restoreKnob(t, func() { swapSettle = prev })
r := newReplicaSetRig(t, "b", replicaAttempt("released", replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}))
// Copies need an always-on release (appcopies.go): a resident row.
r.rt.Hibernate, r.rt.Kind = false, "instance"
diff --git a/internal/activator/retire_refuse_e2e_test.go b/internal/activator/retire_refuse_e2e_test.go
index e7b910c6f..ba0f41930 100644
--- a/internal/activator/retire_refuse_e2e_test.go
+++ b/internal/activator/retire_refuse_e2e_test.go
@@ -182,7 +182,7 @@ func TestRetiringCopyRefusedInBegin(t *testing.T) {
t.Fatal(err)
}
b := &fakeBackend{}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg1)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg1)
routes := &gatedRoutes{reg: reg1, release: make(chan struct{})}
a.Routes = routes
t.Cleanup(func() {
diff --git a/internal/activator/rootfs_admission_test.go b/internal/activator/rootfs_admission_test.go
index 0bab22eea..cd48effc9 100644
--- a/internal/activator/rootfs_admission_test.go
+++ b/internal/activator/rootfs_admission_test.go
@@ -76,7 +76,7 @@ func harnessService(t *testing.T, h *rootfsCtlHarness) (*Service, *harnessBacken
}
t.Cleanup(func() { reg.Close() })
hb := &harnessBackend{SplitBackend: productionBackend(t, h.eb)}
- a := New(Config{Bucket: "test-bucket", Idle: 400 * time.Millisecond}, hb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: 400 * time.Millisecond}, hb, reg)
clk := &fakeClock{t: time.Unix(1_700_000_000, 0)}
a.now = clk.now
a.gens = true
diff --git a/internal/activator/rootfs_cmd_lease_test.go b/internal/activator/rootfs_cmd_lease_test.go
index c76d3e9a7..667f6c827 100644
--- a/internal/activator/rootfs_cmd_lease_test.go
+++ b/internal/activator/rootfs_cmd_lease_test.go
@@ -189,7 +189,7 @@ func runLeaseService(t *testing.T, routes ...registry.Route) (*Service, *runLeas
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.now = clk.now
a.gens = true
armRootfsForTest(a)
@@ -860,7 +860,7 @@ func (c *hangingRootfsCtl) askedCount() int {
func TestALeaseKillIsBoundedByKillOneShotsBudgets(t *testing.T) {
oldC, oldE := oneShotKillControlBound, roleEmptyBound
oneShotKillControlBound, roleEmptyBound = 200*time.Millisecond, 200*time.Millisecond
- t.Cleanup(func() { oneShotKillControlBound, roleEmptyBound = oldC, oldE })
+ restoreKnob(t, func() { oneShotKillControlBound, roleEmptyBound = oldC, oldE })
const slack = 2 * time.Second
t.Run("the control service hangs", func(t *testing.T) {
diff --git a/internal/activator/rootfs_cmd_test.go b/internal/activator/rootfs_cmd_test.go
index 7ee86b738..0dc1b8551 100644
--- a/internal/activator/rootfs_cmd_test.go
+++ b/internal/activator/rootfs_cmd_test.go
@@ -365,7 +365,7 @@ func awakeHarnessRow(t *testing.T, h *rootfsCtlHarness) (*Service, *runHarnessBa
}
t.Cleanup(func() { reg.Close() })
hb := &runHarnessBackend{harnessBackend: &harnessBackend{SplitBackend: productionBackend(t, h.eb)}, rep: &heldRep{}}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, hb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, hb, reg)
clk := &fakeClock{t: time.Unix(1_700_000_000, 0)}
a.now = clk.now
a.gens = true
@@ -399,7 +399,7 @@ func TestRootfsRunPollsAndStopsTheRootfsUnit(t *testing.T) {
}
old := roleEmptyBound
roleEmptyBound = 300 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
h := newRootfsCtlHarness(t)
h.runProbes()
h.eb.ObservePoll = 20 * time.Millisecond
diff --git a/internal/activator/rootfs_gate_test.go b/internal/activator/rootfs_gate_test.go
index d11363473..5a1c2cf8a 100644
--- a/internal/activator/rootfs_gate_test.go
+++ b/internal/activator/rootfs_gate_test.go
@@ -689,7 +689,7 @@ func TestRootfsPlannedFirstWakeGetsTheRootfsBudget(t *testing.T) {
shrinkHealthBounds(t, 300*time.Millisecond, 2*time.Second, 100*time.Millisecond)
ob, or, ow := firstWakeBudget, firstWakeKillReserve, wakeWaitBound
firstWakeBudget, firstWakeKillReserve, wakeWaitBound = 600*time.Millisecond, 300*time.Millisecond, 100*time.Millisecond
- t.Cleanup(func() { firstWakeBudget, firstWakeKillReserve, wakeWaitBound = ob, or, ow })
+ restoreKnob(t, func() { firstWakeBudget, firstWakeKillReserve, wakeWaitBound = ob, or, ow })
lb, ctl := newRootfsLaunch(t, &fakeSwapBackend{fakeBackend: &fakeBackend{}})
next, good := stagedRootfsIdentity(t, lb.eb, "v2"), stagedRootfsIdentity(t, lb.eb, "v3")
ctl.setServe(serveVersions(t, lb.eb, lb.rt, 900*time.Millisecond, "v2", "v3"))
diff --git a/internal/activator/rootfs_invariants_test.go b/internal/activator/rootfs_invariants_test.go
index 4ead8e42a..6565e9004 100644
--- a/internal/activator/rootfs_invariants_test.go
+++ b/internal/activator/rootfs_invariants_test.go
@@ -652,7 +652,7 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){
"rootfs cmdUnit": func(t *testing.T, r *rootfsProofRig) {
old := roleEmptyBound
roleEmptyBound = 100 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning}
r.ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // the binary unit's answer
u := &cmdUnit{b: r.b, rt: r.rt, role: instancectl.RoleCmd, inv: "inv-r", io: oneShotIO{out: emptyCmdStream(t), errs: emptyCmdStream(t)}}
@@ -679,7 +679,7 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){
"release cmdUnit (StartRelease)": func(t *testing.T, r *rootfsProofRig) {
oldEmpty, oldGrace := roleEmptyBound, cmdAcceptGrace
roleEmptyBound, cmdAcceptGrace = 100*time.Millisecond, 20*time.Millisecond
- t.Cleanup(func() { roleEmptyBound, cmdAcceptGrace = oldEmpty, oldGrace })
+ restoreKnob(t, func() { roleEmptyBound, cmdAcceptGrace = oldEmpty, oldGrace })
id := stagedRootfsIdentity(t, r.b, "v2")
r.ctl.cmdInv = "inv-rel"
r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-rel", State: instancectl.CmdRunning}
@@ -721,7 +721,7 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){
"rootfs worker unitProc": func(t *testing.T, r *rootfsProofRig) {
old := roleEmptyBound
roleEmptyBound = 100 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
unit := instancectl.WorkerUnitName(r.rt.Host, "jobs")
r.mu.Lock()
r.unit[unit] = [2]string{"active", "inv1"}
@@ -785,7 +785,7 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){
func rootfsSessionProofRow(t *testing.T, r *rootfsProofRig) {
old := roleEmptyBound
roleEmptyBound = 100 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
unit := instancectl.RootfsUnitName(instancectl.RoleTTY, r.rt.Host)
r.mu.Lock()
r.unit[unit] = [2]string{"active", "inv-t"}
@@ -851,7 +851,7 @@ func rootfsSessionProofRow(t *testing.T, r *rootfsProofRig) {
func rootfsRunProofRow(t *testing.T, r *rootfsProofRig) {
old := roleEmptyBound
roleEmptyBound = 100 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
r.ctl.cmdInv = "inv-r"
r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning}
r.ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // the binary unit's answer
diff --git a/internal/activator/rootfs_processes_test.go b/internal/activator/rootfs_processes_test.go
index fc4a66657..d306f62e1 100644
--- a/internal/activator/rootfs_processes_test.go
+++ b/internal/activator/rootfs_processes_test.go
@@ -493,7 +493,7 @@ func TestProcessesThroughTheProductionBackend(t *testing.T) {
logs := captureLogLines(t)
eb, _ := newRootfsBackend(t)
pb := productionBackend(t, eb)
- a := New(Config{Bucket: "test-bucket"}, pb, nil)
+ a := newTrackedService(Config{Bucket: "test-bucket"}, pb, nil)
t.Cleanup(func() { a.Shutdown(context.Background()) })
rt := rootfsRoute(eb)
id := stageDeclared(t, eb, "v2", declaredProcs(), nil)
diff --git a/internal/activator/rootfs_release_backend_test.go b/internal/activator/rootfs_release_backend_test.go
index 21a16e098..6cb75a20f 100644
--- a/internal/activator/rootfs_release_backend_test.go
+++ b/internal/activator/rootfs_release_backend_test.go
@@ -69,7 +69,7 @@ func shrinkCmdBounds(t *testing.T) {
t.Helper()
oldEmpty, oldGrace := roleEmptyBound, cmdAcceptGrace
roleEmptyBound, cmdAcceptGrace = 200*time.Millisecond, 50*time.Millisecond
- t.Cleanup(func() { roleEmptyBound, cmdAcceptGrace = oldEmpty, oldGrace })
+ restoreKnob(t, func() { roleEmptyBound, cmdAcceptGrace = oldEmpty, oldGrace })
}
// settleAtEnd stops and proves u gone when the test ends.
diff --git a/internal/activator/rootfs_resident_lease_test.go b/internal/activator/rootfs_resident_lease_test.go
index 7fc599c45..76e5122c4 100644
--- a/internal/activator/rootfs_resident_lease_test.go
+++ b/internal/activator/rootfs_resident_lease_test.go
@@ -101,7 +101,7 @@ func residentKillService(t *testing.T, routes ...registry.Route) (*Service, *kil
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, kb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, kb, reg)
a.now = clk.now
a.gens = true
armRootfsForTest(a)
@@ -117,7 +117,7 @@ func shrinkDrainBudget(t *testing.T, d time.Duration) {
t.Helper()
old := residentDrainBudget
residentDrainBudget = d
- t.Cleanup(func() { residentDrainBudget = old })
+ restoreKnob(t, func() { residentDrainBudget = old })
}
func indexWithPrefix(events []string, prefix string) int {
diff --git a/internal/activator/rootfs_resident_test.go b/internal/activator/rootfs_resident_test.go
index e9cd92dae..953fb1088 100644
--- a/internal/activator/rootfs_resident_test.go
+++ b/internal/activator/rootfs_resident_test.go
@@ -105,7 +105,7 @@ func shrinkResidentPoll(t *testing.T, d time.Duration) {
t.Helper()
old := residentPoll
residentPoll = d
- t.Cleanup(func() { residentPoll = old })
+ restoreKnob(t, func() { residentPoll = old })
}
// residentOf is a copy of host's residency state (zero when none).
diff --git a/internal/activator/rootfs_staged_test.go b/internal/activator/rootfs_staged_test.go
index e9d7a9b34..42132628c 100644
--- a/internal/activator/rootfs_staged_test.go
+++ b/internal/activator/rootfs_staged_test.go
@@ -212,7 +212,7 @@ func rootfsPlanned(t *testing.T, b Backend, plan WakePlan, runtime string) (*Ser
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.gens = true
armRootfsForTest(a)
evs := &genLog{}
@@ -229,7 +229,7 @@ func shrinkHealthBounds(t *testing.T, binary, rootfs, floor time.Duration) {
t.Helper()
b, r, f := spawnHealthTimeout, rootfsHealthTimeout, firstWakeMinVerdict
spawnHealthTimeout, rootfsHealthTimeout, firstWakeMinVerdict = binary, rootfs, floor
- t.Cleanup(func() { spawnHealthTimeout, rootfsHealthTimeout, firstWakeMinVerdict = b, r, f })
+ restoreKnob(t, func() { spawnHealthTimeout, rootfsHealthTimeout, firstWakeMinVerdict = b, r, f })
}
// noBinaryStart fails t if root was asked for any binary unit's start.
diff --git a/internal/activator/rootfs_swap_release_test.go b/internal/activator/rootfs_swap_release_test.go
index e98189aff..b522ddb7a 100644
--- a/internal/activator/rootfs_swap_release_test.go
+++ b/internal/activator/rootfs_swap_release_test.go
@@ -1007,7 +1007,7 @@ func TestReleaseRerunsAfterAnAgentRestart(t *testing.T) {
}
// The seam between the pass and swapOverlap: the agent restarts. A new
// Service over the same registry and backend wakes the incumbent.
- b := New(Config{Bucket: "test-bucket", Idle: time.Hour}, f.rb, f.reg)
+ b := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, f.rb, f.reg)
b.gens, b.now = true, f.clk.now
b.genHealth = func(context.Context, Gen) error { return nil }
b.Logs = f.sink
diff --git a/internal/activator/rootfs_test.go b/internal/activator/rootfs_test.go
index 03fdb7a82..39471cc0f 100644
--- a/internal/activator/rootfs_test.go
+++ b/internal/activator/rootfs_test.go
@@ -383,7 +383,7 @@ func TestRootfsStartTreatsA502AsAStartThatMayHaveRun(t *testing.T) {
func TestRootfsGenerationStartFailureStopsAndProvesTheGeneration(t *testing.T) {
old := roleEmptyBound
roleEmptyBound = 60 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
for _, tc := range []struct {
name string
// rootUnproven: root's kill answered ErrGenUnproven (files kept);
@@ -454,7 +454,7 @@ func TestRootfsGenerationStartFailureStopsAndProvesTheGeneration(t *testing.T) {
func TestTheReaperNeverProvesARootfsGenerationGoneThroughTheBinaryUnit(t *testing.T) {
old := roleEmptyBound
roleEmptyBound = 60 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
b, ctl := newRootfsBackend(t)
b.GenContainment = true
b.Control = fakeGenControl{ctl}
@@ -760,7 +760,7 @@ func TestRootfsHealthBoundIs120Seconds(t *testing.T) {
// the rootfs line, and the unit is stopped through the rootfs verb.
old := rootfsHealthTimeout
rootfsHealthTimeout = 200 * time.Millisecond
- t.Cleanup(func() { rootfsHealthTimeout = old })
+ restoreKnob(t, func() { rootfsHealthTimeout = old })
b, ctl := newRootfsBackend(t)
rt := rootfsRoute(b)
began := time.Now()
@@ -894,7 +894,7 @@ func TestRootfsCmdUnitPollsStopsAndProvesTheRootfsUnit(t *testing.T) {
}
old := roleEmptyBound
roleEmptyBound = 50 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning}
ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // what the BINARY unit's poll would say
u := &cmdUnit{b: b, rt: rt, role: instancectl.RoleCmd, inv: "inv-r", io: oneShotIO{out: emptyCmdStream(t), errs: emptyCmdStream(t)}}
diff --git a/internal/activator/rootfs_wake_release_test.go b/internal/activator/rootfs_wake_release_test.go
index cb4a20a93..4a9359a8f 100644
--- a/internal/activator/rootfs_wake_release_test.go
+++ b/internal/activator/rootfs_wake_release_test.go
@@ -276,7 +276,7 @@ func (r *wakeRelRig) service(t *testing.T) *Service {
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, r.b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, r.b, reg)
a.now = r.clk.now
a.gens = true
armRootfsForTest(a)
diff --git a/internal/activator/rootfsdb_test.go b/internal/activator/rootfsdb_test.go
index 8e1003819..39ea4b81e 100644
--- a/internal/activator/rootfsdb_test.go
+++ b/internal/activator/rootfsdb_test.go
@@ -246,14 +246,14 @@ func bucketServiceOn(t *testing.T, rig *bucketRig, bucket release.Store) (*Servi
ctl.setServe(serveVersions(t, eb, rt, 0, "v1")) // serves, never opens CARLOS_DB
old := restoreReplica
restoreReplica = func(ctx context.Context, dbPath, _, _, _ string) (bool, error) { return rig.restore(ctx, dbPath) }
- t.Cleanup(func() { restoreReplica = old })
+ restoreKnob(t, func() { restoreReplica = old })
bb := &bucketBackend{ExecBackend: eb, rig: rig}
reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, bb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, bb, reg)
a.gens = true
armRootfsForTest(a)
t.Cleanup(func() { a.Shutdown(context.Background()) })
diff --git a/internal/activator/rootfsrelease_test.go b/internal/activator/rootfsrelease_test.go
index 21696bfc3..d4b82918e 100644
--- a/internal/activator/rootfsrelease_test.go
+++ b/internal/activator/rootfsrelease_test.go
@@ -612,7 +612,7 @@ func newReleaseRig(t *testing.T) *releaseRig {
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.now = clk.now
sink := &rootfsSink{}
a.Logs = sink
@@ -728,7 +728,7 @@ func shrinkRelease(t *testing.T, lead, recheck time.Duration) {
t.Helper()
oldLead, oldRecheck, oldPoll, oldSettle := releaseStopLead, releaseLeaseRecheck, releasePollRetry, releaseSettleRetry
releaseStopLead, releaseLeaseRecheck, releasePollRetry, releaseSettleRetry = lead, recheck, 10*time.Millisecond, 20*time.Millisecond
- t.Cleanup(func() {
+ restoreKnob(t, func() {
releaseStopLead, releaseLeaseRecheck, releasePollRetry, releaseSettleRetry = oldLead, oldRecheck, oldPoll, oldSettle
})
}
@@ -1467,7 +1467,7 @@ func TestEveryReleaseResultIsClassified(t *testing.T) {
// read every result the same way. Only a failure is the hold's
// SwapDown and B's recorded failure; every other result abandons the
// hold and records nothing of B, with execution as the release left it.
- a := New(Config{Bucket: "test-bucket"}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{Bucket: "test-bucket"}, &fakeBackend{}, nil)
boot := release.StagedIdentity{Version: "v2", StagedPath: "/opt/carlos/versions/v2/app", Digest: "bb22"}
rt := testRoute("shop.example.com")
rt.Runtime = registry.RuntimeRootfsV1
@@ -1571,7 +1571,7 @@ func newConsumerRig(t *testing.T, gens bool) *consumerRig {
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &releaseCmdFake{cmdFakeBackend: cb, rel: rel}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &releaseCmdFake{cmdFakeBackend: cb, rel: rel}, reg)
a.now = clk.now
a.gens = gens
sink := &rootfsSink{}
diff --git a/internal/activator/rootfsworkers_backend_test.go b/internal/activator/rootfsworkers_backend_test.go
index 1517e833e..c97570b4e 100644
--- a/internal/activator/rootfsworkers_backend_test.go
+++ b/internal/activator/rootfsworkers_backend_test.go
@@ -455,7 +455,7 @@ func TestRootfsWorkerIdentity(t *testing.T) {
func TestRootfsWorkerStopAnswers(t *testing.T) {
old := roleEmptyBound
roleEmptyBound = 150 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
b, ctl, rt, units := newWorkerBackend(t)
unit := instancectl.WorkerUnitName(rt.Host, "jobs")
units.stopEmpties = false
diff --git a/internal/activator/rootfsworkers_test.go b/internal/activator/rootfsworkers_test.go
index 970caa03c..76ba379e1 100644
--- a/internal/activator/rootfsworkers_test.go
+++ b/internal/activator/rootfsworkers_test.go
@@ -379,7 +379,7 @@ func newWorkerRig(t *testing.T, rt registry.Route, workers ...string) *workerRig
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, wb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, wb, reg)
a.now = clk.now
lc := &leaseClock{t0: time.Now()}
a.leaseNow = lc.now
@@ -1556,7 +1556,7 @@ func TestRootfsWorkersReport(t *testing.T) {
func TestWorkersThroughTheProductionBackendInTheService(t *testing.T) {
b, ctl, rt, units := newWorkerBackend(t)
pb := productionBackend(t, b)
- a := New(Config{Bucket: "test-bucket"}, pb, nil)
+ a := newTrackedService(Config{Bucket: "test-bucket"}, pb, nil)
armRootfsForTest(a)
t.Cleanup(func() { a.Shutdown(context.Background()) })
web, g := startWorkerWeb(t, b, ctl, rt, units, "SHOP_MODE=live\n")
@@ -1760,7 +1760,7 @@ func TestWorkerGateStrayRule(t *testing.T) {
// watch (or with a replica that has no lease signal, which the tick
// watches).
func TestRootfsWorkerInstallNeedsTheLeaseWatch(t *testing.T) {
- a := New(Config{Bucket: "test-bucket"}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{Bucket: "test-bucket"}, &fakeBackend{}, nil)
signal := newOwnedRep(&fakeRep{}, time.Now().Add(time.Hour))
t.Cleanup(func() { signal.timer.Stop() })
lost := &fakeRep{}
@@ -1811,7 +1811,7 @@ func shrinkWorkerBounds(t *testing.T, start, proof time.Duration) {
t.Helper()
oldStart, oldProof := workerStartBound, workerProofBound
workerStartBound, workerProofBound = start, proof
- t.Cleanup(func() { workerStartBound, workerProofBound = oldStart, oldProof })
+ restoreKnob(t, func() { workerStartBound, workerProofBound = oldStart, oldProof })
}
// [C7; Astra W1 r1 P1, r2 P2] Every worker is stopped and proven before
diff --git a/internal/activator/seedplace_linux_test.go b/internal/activator/seedplace_linux_test.go
index 513945181..bdb9ba45f 100644
--- a/internal/activator/seedplace_linux_test.go
+++ b/internal/activator/seedplace_linux_test.go
@@ -82,7 +82,7 @@ func noOwnReplica(t *testing.T) {
t.Helper()
old := hasOwnReplica
hasOwnReplica = func(context.Context, string, string, string) (bool, error) { return false, nil }
- t.Cleanup(func() { hasOwnReplica = old })
+ restoreKnob(t, func() { hasOwnReplica = old })
}
func TestSeededRestorePlacesTheSnapshot(t *testing.T) {
@@ -338,7 +338,7 @@ func countOwnReplicaLists(t *testing.T, has bool) *int {
n := 0
old := hasOwnReplica
hasOwnReplica = func(context.Context, string, string, string) (bool, error) { n++; return has, nil }
- t.Cleanup(func() { hasOwnReplica = old })
+ restoreKnob(t, func() { hasOwnReplica = old })
return &n
}
diff --git a/internal/activator/settle_test.go b/internal/activator/settle_test.go
index 61df391ef..92275d040 100644
--- a/internal/activator/settle_test.go
+++ b/internal/activator/settle_test.go
@@ -56,7 +56,7 @@ func (p *cancelOnPoll) Exited() bool {
func TestSwapCanarySettle(t *testing.T) {
old := swapSettle
- t.Cleanup(func() { swapSettle = old })
+ restoreKnob(t, func() { swapSettle = old })
t.Run("exit during the settle fails the build", func(t *testing.T) {
swapSettle = 2 * time.Second
@@ -112,7 +112,7 @@ func TestSwapCanarySettle(t *testing.T) {
func TestSwapIntentionalStopDuringSettleIsNotAFailure(t *testing.T) {
old := swapSettle
swapSettle = 5 * time.Second
- t.Cleanup(func() { swapSettle = old })
+ restoreKnob(t, func() { swapSettle = old })
for _, tc := range []struct {
name string
stop func(f *swapFixture)
diff --git a/internal/activator/shuttingdown_answer_test.go b/internal/activator/shuttingdown_answer_test.go
index aebe16b9a..2df9fd9b3 100644
--- a/internal/activator/shuttingdown_answer_test.go
+++ b/internal/activator/shuttingdown_answer_test.go
@@ -23,7 +23,7 @@ func TestShuttingDownAnswersRetryAfter(t *testing.T) {
asForwarded(t)
}
b := &fakeBackend{}
- a := New(Config{}, b, nil)
+ a := newTrackedService(Config{}, b, nil)
a.mu.Lock()
a.shuttingDown = true
a.mu.Unlock()
diff --git a/internal/activator/size_live_test.go b/internal/activator/size_live_test.go
index 31bef3d86..8000db255 100644
--- a/internal/activator/size_live_test.go
+++ b/internal/activator/size_live_test.go
@@ -679,7 +679,7 @@ func (s *sizingBackend) ResizeLive(_ context.Context, _ registry.Route, size cgr
func TestPendingStopKeepsTheLeaseWhileAResizeRuns(t *testing.T) {
prev := opJoinBound
opJoinBound = 100 * time.Millisecond
- t.Cleanup(func() { opJoinBound = prev })
+ restoreKnob(t, func() { opJoinBound = prev })
for _, gens := range []bool{true, false} {
name := "generations off"
if gens {
diff --git a/internal/activator/startrule_test.go b/internal/activator/startrule_test.go
index 0bc1f8e01..2191c718c 100644
--- a/internal/activator/startrule_test.go
+++ b/internal/activator/startrule_test.go
@@ -207,7 +207,7 @@ func wakeOn(t *testing.T, eb *ExecBackend, rt registry.Route, tweak func(*ruleBa
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, rb, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, rb, reg)
release, err := a.beginRequest(context.Background(), rt)
if err == nil {
release()
@@ -470,7 +470,7 @@ func recordDurability(t *testing.T, fail func(dir string) error) *[]string {
}
return prevSync(dir)
}
- t.Cleanup(func() { setAsideRename, durableSync = prevRename, prevSync })
+ restoreKnob(t, func() { setAsideRename, durableSync = prevRename, prevSync })
return &ops
}
diff --git a/internal/activator/startup_test.go b/internal/activator/startup_test.go
index d1c29e03b..53fda5399 100644
--- a/internal/activator/startup_test.go
+++ b/internal/activator/startup_test.go
@@ -14,8 +14,8 @@ import (
func TestStartupWaitUsesWakeTimeoutResponse(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 20 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
- a := New(Config{}, &fakeBackend{}, nil)
+ restoreKnob(t, func() { wakeWaitBound = old })
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
a.Startup = make(chan struct{})
defer a.lifeStop()
rt := registry.Route{Host: "shop.example.com", Kind: "instance", Hibernate: true}
@@ -32,8 +32,8 @@ func TestStartupWaitUsesWakeTimeoutResponse(t *testing.T) {
func TestStartupBlocksWorkerAndSidecarAdmission(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 20 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
- a := New(Config{}, &fakeBackend{}, nil)
+ restoreKnob(t, func() { wakeWaitBound = old })
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
a.Startup = make(chan struct{})
defer a.lifeStop()
rt := registry.Route{Host: "shop.example.com", Kind: "instance", Hibernate: true}
@@ -56,7 +56,7 @@ func TestStartupBlocksWorkerAndSidecarAdmission(t *testing.T) {
func TestStartupShutdownAnswersServiceUnavailable(t *testing.T) {
for _, ready := range []bool{false, true} {
t.Run(map[bool]string{false: "held", true: "released"}[ready], func(t *testing.T) {
- a := New(Config{}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
started := make(chan struct{})
a.Startup = started
if ready {
@@ -93,7 +93,7 @@ func (s startupRoutes) Get(host string) (*registry.Route, error) {
func TestStartupHeldRequestRefusesStaleUpstream(t *testing.T) {
t.Parallel()
for _, moved := range []bool{false, true} {
- a := New(Config{}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
ready := make(chan struct{})
a.Startup = ready
rt := registry.Route{Host: "shop.example.com", Kind: "instance", Hibernate: true, Socket: "/run/carlos/shop.example.com.sock"}
@@ -131,7 +131,7 @@ func TestStartupHeldRequestRefusesStaleUpstream(t *testing.T) {
// startup is still checked; one long after it is not.
func TestStartupClosedNearStartupRefusesStaleUpstream(t *testing.T) {
for _, late := range []bool{false, true} {
- a := New(Config{}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
ready := make(chan struct{})
close(ready)
a.Startup = ready
diff --git a/internal/activator/stop_returned_sidecar_test.go b/internal/activator/stop_returned_sidecar_test.go
index 43b0a44ee..3d4dcec88 100644
--- a/internal/activator/stop_returned_sidecar_test.go
+++ b/internal/activator/stop_returned_sidecar_test.go
@@ -43,7 +43,7 @@ func shrinkSidecarJoinWait(t *testing.T) {
t.Helper()
prev := sidecarStartJoinWait
sidecarStartJoinWait = 50 * time.Millisecond
- t.Cleanup(func() { sidecarStartJoinWait = prev })
+ restoreKnob(t, func() { sidecarStartJoinWait = prev })
}
// Fix wave 1, item 1 (Astra final review 1, finding 1): the missed-join
diff --git a/internal/activator/swap_admit_test.go b/internal/activator/swap_admit_test.go
index de3dc3e51..dffb3de81 100644
--- a/internal/activator/swap_admit_test.go
+++ b/internal/activator/swap_admit_test.go
@@ -144,7 +144,7 @@ func TestOwnershipIsCheckedApartFromSupersession(t *testing.T) {
// Claims off: hostwrite's legacy work. The check runs alone, under the
// entry lock that fn takes itself.
func TestAdmitClaimsOffRunsTheCheckAlone(t *testing.T) {
- a := New(Config{}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{}, &fakeBackend{}, nil)
work, err := a.selectWork(context.Background(), "h.example.com")
if err != nil || !hostwrite.Legacy(work) {
t.Fatalf("claims off selected %T, %v; want the legacy work", work, err)
@@ -161,7 +161,7 @@ func TestAdmitClaimsOffRunsTheCheckAlone(t *testing.T) {
func TestAdmitClaimsOnValidatesFirstAndNeverFallsBack(t *testing.T) {
ctx := context.Background()
w := &swapWork{}
- a := New(Config{HostWrites: hostwrite.Config{Enabled: true, Selector: &swapSelector{work: w}}}, &fakeBackend{}, nil)
+ a := newTrackedService(Config{HostWrites: hostwrite.Config{Enabled: true, Selector: &swapSelector{work: w}}}, &fakeBackend{}, nil)
work, err := a.selectWork(ctx, "h.example.com")
if err != nil || hostwrite.Legacy(work) {
t.Fatalf("claims on selected %T, %v", work, err)
diff --git a/internal/activator/swap_fixture_test.go b/internal/activator/swap_fixture_test.go
index 78afa4b3d..a59ea52ed 100644
--- a/internal/activator/swap_fixture_test.go
+++ b/internal/activator/swap_fixture_test.go
@@ -278,7 +278,7 @@ func newSwapFixtureOn(t *testing.T, wrap func(*fakeSwapBackend) Backend) *swapFi
if wrap != nil {
be = wrap(b)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, be, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, be, reg)
a.gens = true // plan 1's switch, as plan 5 sets it from CARLOS_SWAP
a.now = clk.now
a.genHealth = func(context.Context, Gen) error { return nil }
diff --git a/internal/activator/swap_hold_test.go b/internal/activator/swap_hold_test.go
index ae11efc82..a90f87c2c 100644
--- a/internal/activator/swap_hold_test.go
+++ b/internal/activator/swap_hold_test.go
@@ -103,7 +103,7 @@ func (c *doneAskedCtx) Done() <-chan struct{} {
// fails the attempt nor halts the rollout.
func TestSwapHoldCanarySettles(t *testing.T) {
old := swapSettle
- t.Cleanup(func() { swapSettle = old })
+ restoreKnob(t, func() { swapSettle = old })
start := func(t *testing.T, f *swapFixture) (chan SwapResult, Gen, *fakeProc) {
t.Helper()
at := f.attempt(ModeHold)
@@ -586,7 +586,7 @@ func TestSwapHoldReleasesItsCallerWhileTheStopIsPending(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
old := wakeWaitBound
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
f := newSwapFixture(t)
if errors.Is(tc.want, errHoldStopSlow) {
wakeWaitBound = 100 * time.Millisecond
diff --git a/internal/activator/swap_review_test.go b/internal/activator/swap_review_test.go
index df2a4c59b..0cb847b84 100644
--- a/internal/activator/swap_review_test.go
+++ b/internal/activator/swap_review_test.go
@@ -24,7 +24,7 @@ func TestSwapWitnessAgentRestartMidSwap(t *testing.T) {
t.Helper()
f.b.execVerFn = func() string { return "v2" } // root installed v2
gensBefore, _, _ := f.b.calls()
- a2 := New(Config{Bucket: "test-bucket", Idle: time.Hour}, f.b, f.reg)
+ a2 := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, f.b, f.reg)
a2.gens = true
arrangeAwake(t, a2, testRoute(f.host))
if got := f.b.startCount(); got != 2 {
@@ -196,7 +196,7 @@ func TestSwapNeverHealthyAppKeepsTheIncumbentServing(t *testing.T) {
}
old := spawnHealthTimeout
spawnHealthTimeout = 600 * time.Millisecond
- t.Cleanup(func() { spawnHealthTimeout = old })
+ restoreKnob(t, func() { spawnHealthTimeout = old })
f := newSwapFixture(t)
f.a.genHealth = nil // the real check: GET / through the generation's handle
diff --git a/internal/activator/swap_sim_test.go b/internal/activator/swap_sim_test.go
index 161bfe3bd..e3c8f4c5e 100644
--- a/internal/activator/swap_sim_test.go
+++ b/internal/activator/swap_sim_test.go
@@ -67,7 +67,7 @@ func TestSwapInvariants(t *testing.T) {
}
oldSettle, oldJoin := swapSettle, opJoinBound
swapSettle, opJoinBound = 2*time.Millisecond, 3*time.Second
- t.Cleanup(func() { swapSettle, opJoinBound = oldSettle, oldJoin })
+ restoreKnob(t, func() { swapSettle, opJoinBound = oldSettle, oldJoin })
// The Service's own log lines go into the seed's event log, so a failure
// prints them in order with the model's events, and a passing sweep
// prints nothing.
@@ -979,7 +979,7 @@ func simulateSwapOnce(seed int, staged map[string]simArtifact, sockDir string, s
}
sb := &simBackend{w: w, dir: sockDir, reps: map[string]*simRep{}, wakes: map[string]int{}}
clk := &fakeClock{t: time.Unix(1_700_000_000, 0)}
- a := New(Config{Bucket: "sim", Idle: time.Hour}, sb, simDue{})
+ a := newTrackedService(Config{Bucket: "sim", Idle: time.Hour}, sb, simDue{})
a.gens = w.gensOn
a.now = w.simHeldClock(clk.now)
// I4's record: every leg this Service registers, under a.mu.
diff --git a/internal/activator/tunnel_refuse_test.go b/internal/activator/tunnel_refuse_test.go
index 1f10e8c4c..a5a5f28cc 100644
--- a/internal/activator/tunnel_refuse_test.go
+++ b/internal/activator/tunnel_refuse_test.go
@@ -57,7 +57,7 @@ func newRefuseBox(t *testing.T, rt registry.Route) *refuseBox {
if err != nil {
t.Fatal(err)
}
- x.a = New(Config{Bucket: "test-bucket", Idle: time.Hour}, x.b, reg)
+ x.a = newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, x.b, reg)
x.a.Startup = make(chan struct{})
conns := make(chan *http2.ClientConn, 1)
hub := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -166,7 +166,7 @@ func TestServeRefusesBeforeAppRead(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.Startup = make(chan struct{})
a.lifeStop()
w := httptest.NewRecorder()
diff --git a/internal/activator/unitproc_test.go b/internal/activator/unitproc_test.go
index 96640e9f1..fdbd1305f 100644
--- a/internal/activator/unitproc_test.go
+++ b/internal/activator/unitproc_test.go
@@ -662,7 +662,7 @@ func TestSeedUnitFailureStopsBeforeCleanupAndKeepsTheDBWhenProcessesRemain(t *te
}
old := roleEmptyBound
roleEmptyBound = 300 * time.Millisecond
- t.Cleanup(func() { roleEmptyBound = old })
+ restoreKnob(t, func() { roleEmptyBound = old })
ctl := &fakeControl{seed: instancectl.SeedResponse{InvocationID: "s1", Result: "exit-code", Status: "3", Code: "exited"}}
unit := &fakeUnit{}
b, rt := nestedBackend(t, ctl, unit)
diff --git a/internal/activator/wakecheck_claim_linux_test.go b/internal/activator/wakecheck_claim_linux_test.go
index bf69a1100..f961b2da0 100644
--- a/internal/activator/wakecheck_claim_linux_test.go
+++ b/internal/activator/wakecheck_claim_linux_test.go
@@ -61,7 +61,7 @@ func newHeldClaimed(t *testing.T, live, hashed string) *heldClaimed {
}
var mu sync.Mutex
reads := 0
- c.a = New(Config{Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box", Bucket: "data",
+ c.a = newTrackedService(Config{Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box", Bucket: "data",
Read: func(context.Context, string) (hostclaim.Observed, error) {
mu.Lock()
defer mu.Unlock()
diff --git a/internal/activator/wakecheck_test.go b/internal/activator/wakecheck_test.go
index 70c4df19a..50948ddbd 100644
--- a/internal/activator/wakecheck_test.go
+++ b/internal/activator/wakecheck_test.go
@@ -30,7 +30,7 @@ func shrinkWakeWait(t *testing.T, d time.Duration) {
t.Helper()
old := wakeWaitBound
wakeWaitBound = d
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
}
// shrinkHeldPoll sets how often a held wake polls while it waits, for one
@@ -40,7 +40,7 @@ func shrinkHeldPoll(t *testing.T, d time.Duration) {
t.Helper()
old := heldPoll
heldPoll = d
- t.Cleanup(func() { heldPoll = old })
+ restoreKnob(t, func() { heldPoll = old })
}
// asks records RequestStage calls as host@build.
@@ -548,7 +548,7 @@ func TestAHeldUnitRowRefusesALinkThatMovedAfterTheWait(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, split, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, split, reg)
ur := identityRoute(t, "u.example.com")
ur.Backing = registry.BackingUnit
routes := &countingRoutes{rt: ur}
diff --git a/internal/activator/wakeidentity_test.go b/internal/activator/wakeidentity_test.go
index ff2e1aa30..ee8e23e49 100644
--- a/internal/activator/wakeidentity_test.go
+++ b/internal/activator/wakeidentity_test.go
@@ -603,7 +603,7 @@ func TestANestedUnversionedLinkWithNoHookWakesAsToday(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &leaselessExec{ExecBackend: eb, fb: &fakeBackend{}}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &leaselessExec{ExecBackend: eb, fb: &fakeBackend{}}, reg)
done, err := a.beginRequest(context.Background(), rt)
if err != nil {
t.Fatalf("a nested unversioned link with no hook did not wake: %v\nroot was asked:\n%s", err, ctl.joined())
@@ -674,7 +674,7 @@ func TestAUnitRouteOnASplitBackendKeepsTodaysWake(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, split, reg) // as agent.go builds it
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, split, reg) // as agent.go builds it
l := &execLog{}
a.BeforeExec = l.hook
unit.restoreFresh = true
@@ -857,7 +857,7 @@ func sidecarActivator(t *testing.T, live string) (*Service, *planGenBackend) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
b.sidecarStaged = true
if live != "" {
b.fakeBackend.setIdentity(live)
diff --git a/internal/activator/wakeplan_test.go b/internal/activator/wakeplan_test.go
index ccf333ea7..279fee7ad 100644
--- a/internal/activator/wakeplan_test.go
+++ b/internal/activator/wakeplan_test.go
@@ -187,7 +187,7 @@ func planActivator(t *testing.T, plan WakePlan) (*Service, *planGenBackend, *gen
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.gens = true // plan 1's switch, as CARLOS_SWAP=overlap sets it before New
evs := &genLog{}
a.OnGen = evs.add
@@ -200,7 +200,7 @@ func shrinkFirstWake(t *testing.T, budget, reserve, settle time.Duration) {
t.Helper()
b, r, s, k := firstWakeBudget, firstWakeKillReserve, firstWakeSettle, firstWakeKillBound
firstWakeBudget, firstWakeKillReserve, firstWakeSettle = budget, reserve, settle
- t.Cleanup(func() { firstWakeBudget, firstWakeKillReserve, firstWakeSettle, firstWakeKillBound = b, r, s, k })
+ restoreKnob(t, func() { firstWakeBudget, firstWakeKillReserve, firstWakeSettle, firstWakeKillBound = b, r, s, k })
}
func TestFirstWakeFallsBackToTheGoodBuildWithinTheBudget(t *testing.T) {
@@ -480,7 +480,7 @@ func TestAFirstWakeThatSurvivesSettles(t *testing.T) {
func TestFirstWakeWaitersGetTheLongerBudget(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 100 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
shrinkFirstWake(t, 600*time.Millisecond, 200*time.Millisecond, time.Millisecond)
dir := t.TempDir()
good, next := stagedID(t, dir, "v1"), stagedID(t, dir, "v2")
@@ -540,7 +540,7 @@ func shrinkClaimStartBackoff(t *testing.T, d time.Duration) {
t.Helper()
old := claimStartBackoff
claimStartBackoff = d
- t.Cleanup(func() { claimStartBackoff = old })
+ restoreKnob(t, func() { claimStartBackoff = old })
}
// PF17: every claims-on launch refuses on this base (RoleLaunch.Start
@@ -575,7 +575,7 @@ func TestAPlannedClaimedWakeRefusesAtTheLaunchRecordingNothing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box",
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour, HostWrites: hostwrite.Config{Enabled: true}, Claims: &ClaimRuntime{Box: "box",
Read: func(context.Context, string) (hostclaim.Observed, error) {
if reads.Add(1) == 1 {
return obs, nil
@@ -697,7 +697,7 @@ func TestAPlannedFirstWakeOnTheRealExecBackendFallsBackInTime(t *testing.T) {
t.Run(layout, func(t *testing.T) {
oldBound := wakeWaitBound
wakeWaitBound = time.Second
- t.Cleanup(func() { wakeWaitBound = oldBound })
+ restoreKnob(t, func() { wakeWaitBound = oldBound })
shrinkFirstWake(t, 4*time.Second, 2*time.Second, time.Millisecond) // B's health window: 2 s
// The floor shrinks with the window, or B (2 s) would never be
// exec'd under the spec's 20 s floor.
@@ -723,7 +723,7 @@ func TestAPlannedFirstWakeOnTheRealExecBackendFallsBackInTime(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.gens = true
evs := &genLog{}
a.OnGen = evs.add
@@ -1260,7 +1260,7 @@ func shrinkVerdictFloor(t *testing.T, floor time.Duration) {
t.Helper()
old := firstWakeMinVerdict
firstWakeMinVerdict = floor
- t.Cleanup(func() { firstWakeMinVerdict = old })
+ restoreKnob(t, func() { firstWakeMinVerdict = old })
}
// slowFirstCheck is a plan's selection gate whose first call, checkPlan's
diff --git a/internal/activator/wakerecord_refused_test.go b/internal/activator/wakerecord_refused_test.go
index c94a829d7..6d8fabd50 100644
--- a/internal/activator/wakerecord_refused_test.go
+++ b/internal/activator/wakerecord_refused_test.go
@@ -53,7 +53,7 @@ func refusedWake(t *testing.T, eb *ExecBackend, rt registry.Route) (error, []str
t.Fatal(err)
}
t.Cleanup(func() { reg.Close() })
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &execIdentityBackend{fakeBackend: fb, eb: eb}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &execIdentityBackend{fakeBackend: fb, eb: eb}, reg)
l := &execLog{}
a.BeforeExec = l.hook
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
diff --git a/internal/activator/wakeslots_test.go b/internal/activator/wakeslots_test.go
index cddc0b409..b137b59c8 100644
--- a/internal/activator/wakeslots_test.go
+++ b/internal/activator/wakeslots_test.go
@@ -19,7 +19,7 @@ func testActivatorSlots(t *testing.T, slots int) (*Service, *fakeBackend) {
if err != nil {
t.Fatalf("open registry: %v", err)
}
- return New(Config{Bucket: "test-bucket", Idle: time.Minute, WakeSlots: slots}, b, reg), b
+ return newTrackedService(Config{Bucket: "test-bucket", Idle: time.Minute, WakeSlots: slots}, b, reg), b
}
// A burst of first requests to different hosts (#524) wakes at most
diff --git a/internal/activator/worker_gen_test.go b/internal/activator/worker_gen_test.go
index 7e3c02e58..9a1fd1bfa 100644
--- a/internal/activator/worker_gen_test.go
+++ b/internal/activator/worker_gen_test.go
@@ -18,7 +18,7 @@ func TestWorkerGenerations(t *testing.T) {
a.gens = on
old := sidecarSettle
sidecarSettle = 20 * time.Millisecond
- t.Cleanup(func() { sidecarSettle = old })
+ restoreKnob(t, func() { sidecarSettle = old })
rt := testWorkerRoute("bot.example.com")
if err := a.WakeWorker(rt); err != nil {
t.Fatal(err)
@@ -154,7 +154,7 @@ func TestWorkerTerminationProvesItsHostCgroup(t *testing.T) {
t.Run("a failed worker wake keeps its lease", func(t *testing.T) {
old := sidecarSettle
sidecarSettle = 20 * time.Millisecond
- t.Cleanup(func() { sidecarSettle = old })
+ restoreKnob(t, func() { sidecarSettle = old })
a, b, _, _ := testActivator(t, time.Hour)
a.gens = true
hk := &hostKillBackend{fakeBackend: b, bad: true}
@@ -191,7 +191,7 @@ func TestWorkerTerminationProvesItsHostCgroup(t *testing.T) {
t.Run("a respawn execs nothing beside the old child", func(t *testing.T) {
old := sidecarSettle
sidecarSettle = 20 * time.Millisecond
- t.Cleanup(func() { sidecarSettle = old })
+ restoreKnob(t, func() { sidecarSettle = old })
a, b, clk, _ := testActivator(t, time.Hour)
a.gens = true
hk := &hostKillBackend{fakeBackend: b}
diff --git a/internal/activator/worker_generations_test.go b/internal/activator/worker_generations_test.go
index 16b641228..54dc0a86a 100644
--- a/internal/activator/worker_generations_test.go
+++ b/internal/activator/worker_generations_test.go
@@ -167,7 +167,7 @@ func TestWorkerCapturedBuildSurvivesARestageOfItsReusedName(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: fb, exec: eb}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: fb, exec: eb}, reg)
a.liveVer = eb.LiveVersion
a.GenerationsFile = release.GenerationsPath(dataDir)
t.Cleanup(func() { a.Shutdown(context.Background()) })
@@ -450,7 +450,7 @@ func TestWorkerFromAChainedLinkIsPublishedByPath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: fb, exec: eb}, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, &realWorkerBackend{fakeBackend: fb, exec: eb}, reg)
a.liveVer = eb.LiveVersion
a.GenerationsFile = release.GenerationsPath(t.TempDir())
t.Cleanup(func() { a.Shutdown(context.Background()) })
diff --git a/internal/activator/worker_identity_test.go b/internal/activator/worker_identity_test.go
index 2a98173f4..e5de224dd 100644
--- a/internal/activator/worker_identity_test.go
+++ b/internal/activator/worker_identity_test.go
@@ -26,7 +26,7 @@ func stagedActivator(t *testing.T) (*Service, *stagedFake, *fakeClock, *registry
if err != nil {
t.Fatalf("open registry: %v", err)
}
- a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
+ a := newTrackedService(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg)
a.now = clk.now
var ver atomic.Value
ver.Store("v1")
diff --git a/internal/activator/worker_respawn_exec_test.go b/internal/activator/worker_respawn_exec_test.go
index 428ca3a66..eee82b8e2 100644
--- a/internal/activator/worker_respawn_exec_test.go
+++ b/internal/activator/worker_respawn_exec_test.go
@@ -136,7 +136,7 @@ func TestAShedRespawnChildIsRetainedUntilItsExitIsProven(t *testing.T) {
if blocked {
old := respawnJoinBound
respawnJoinBound = 100 * time.Millisecond
- t.Cleanup(func() { respawnJoinBound = old })
+ restoreKnob(t, func() { respawnJoinBound = old })
}
a, b, _, _, ver := stagedActivator(t)
a.gens = false
diff --git a/internal/activator/worker_retained_pin_test.go b/internal/activator/worker_retained_pin_test.go
index f97ccf9b2..26586fac2 100644
--- a/internal/activator/worker_retained_pin_test.go
+++ b/internal/activator/worker_retained_pin_test.go
@@ -69,7 +69,7 @@ func generationsHost(t *testing.T, a *Service, path, host string) []string {
func TestARetainedFailedWorkerWakeKeepsItsBuildPinned(t *testing.T) {
old := sidecarSettle
sidecarSettle = 20 * time.Millisecond
- t.Cleanup(func() { sidecarSettle = old })
+ restoreKnob(t, func() { sidecarSettle = old })
a, b, _, _, _ := stagedActivator(t)
a.gens = true
hk := &stagedHostKill{stagedFake: b, bad: true}
diff --git a/internal/activator/workerswap_test.go b/internal/activator/workerswap_test.go
index 8d7caa677..af1de16bb 100644
--- a/internal/activator/workerswap_test.go
+++ b/internal/activator/workerswap_test.go
@@ -231,7 +231,7 @@ func TestReplaceWorkerRunningChildIsNotACleanExit(t *testing.T) {
func TestWakeWorkerWaitsOutAFirstWakeFallback(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 100 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
for _, tc := range []struct {
name string
firstWake bool
@@ -1001,7 +1001,7 @@ func awaitExtensionSeam(t *testing.T, a *Service, release chan struct{}) *atomic
close(release)
waitFor(t, "the failed wake to delete its entry", func() bool { return a.entryCount() == 0 })
}
- t.Cleanup(func() { wakeBoundExtended = old })
+ restoreKnob(t, func() { wakeBoundExtended = old })
return &calls
}
@@ -1013,7 +1013,7 @@ func awaitExtensionSeam(t *testing.T, a *Service, release chan struct{}) *atomic
func TestWakeWorkerAWakeFailingInsideTheExtensionStartsNoSecond(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 50 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
a, b, _, _, _ := stagedActivator(t)
a.gens = true
a.backend = &plannedHostKill{stagedFake: b}
@@ -1049,7 +1049,7 @@ func TestWakeWorkerAWakeFailingInsideTheExtensionStartsNoSecond(t *testing.T) {
func TestBeginAWakeFailingInsideTheExtensionStartsNoSecond(t *testing.T) {
old := wakeWaitBound
wakeWaitBound = 50 * time.Millisecond
- t.Cleanup(func() { wakeWaitBound = old })
+ restoreKnob(t, func() { wakeWaitBound = old })
next := stagedID(t, t.TempDir(), "v2")
a, b, _ := planActivator(t, WakePlan{Boot: next, Mode: ModeOverlap, FirstWake: true})
boom := errors.New("GET / answered 500")