Stop TempDir-backed alert managers in two tests (#2775)

`TestMonitor_HandleAlertResolved_SuppressesRecoveryWhenFiringNeverDelivered`
builds its alert manager with `NewManager()` under
`PULSE_DATA_DIR=t.TempDir()` and never stops it. Firing and resolving
the guest alert queues async active-alert checkpoints that write into
`<dir>/alerts`, so a write can land while, or after, `testing` removes
the directory. That is the same race behind the physical-disk
temperature fixture's `TempDir RemoveAll cleanup: directory not empty`
failure, which main already fixed in e3c6233469. This was the one other
TempDir alert manager left running in `internal/monitoring`.

`TestResolveStorageThresholds_HonorsCanonicalPBSDatastoreAlias` in
`internal/alerts` has the same omission. In a full-package run on
unfixed main its manager's one-minute periodic save recreated the
removed directory (`active-alerts.json` and `intent-pending.json` in a
leftover TempDir).

Both now register `t.Cleanup(Stop)` right after construction. Cleanups
run LIFO, so `Stop` joins the checkpoint and periodic workers before the
directory is removed.

Evidence, on pulse-dev with a 0-3ms delay injected before each async
checkpoint (`go test -overlay`):

- 50 runs of the HandleAlertResolved test: 18 leaked TempDirs on unfixed
main, 0 with this change.
- A full `internal/monitoring` run on unfixed main leaves that test's
directory behind.
- The PBS alias leak appeared in one full `internal/alerts` run; a later
run did not reproduce it because it depends on the one-minute tick
landing after cleanup. The fix follows from the leftover files' contents
and timing, not from a repeatable count.

Test-only change; no runtime code touched.
This commit is contained in:
rcourtman
2026-10-10 08:13:44 +01:00
committed by GitHub
2 changed files with 2 additions and 0 deletions
@@ -12,6 +12,7 @@ import (
// must bridge the two so a UI-written override actually applies (#1591).
func TestResolveStorageThresholds_HonorsCanonicalPBSDatastoreAlias(t *testing.T) {
m := NewManagerWithDataDir(t.TempDir())
t.Cleanup(m.Stop)
m.UpdateConfig(AlertConfig{
Enabled: true,
StorageDefault: HysteresisThreshold{Trigger: 85, Clear: 80},
@@ -1071,6 +1071,7 @@ func TestMonitor_HandleAlertResolved_SuppressesRecoveryWhenFiringNeverDelivered(
notifMgr.SetGroupingWindow(120)
alertMgr := alerts.NewManager()
t.Cleanup(alertMgr.Stop)
cfg := alertMgr.GetConfig()
cfg.Enabled = true
cfg.ActivationState = alerts.ActivationActive