Stop TempDir-backed alert managers in two tests

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 whose worker writes
<dir>/alerts, so a write can land while, or after, testing removes the
directory. This is the same race as the physical-disk temperature
fixture's cleanup failure, which main already fixed; this was the one
other TempDir alert manager in internal/monitoring left running.

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

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

With 0-3ms of delay injected before each async checkpoint (go test
-overlay), 50 runs of the first test leaked 18 TempDirs before this
change and none after. A full internal/monitoring run on unfixed main
also leaves that test's directory behind.
This commit is contained in:
rcourtman
2026-10-10 07:33:57 +01:00
parent 0c0416859b
commit bc6efb5ae2
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