From bc6efb5ae27d7ebef8bafe8dea87b41e27fd4c7f Mon Sep 17 00:00:00 2001
From: rcourtman <8825017+rcourtman@users.noreply.github.com>
Date: Sat, 10 Oct 2026 07:33:57 +0100
Subject: [PATCH] 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
/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.
---
internal/alerts/pbs_datastore_override_alias_test.go | 1 +
internal/monitoring/monitor_alert_handling_test.go | 1 +
2 files changed, 2 insertions(+)
diff --git a/internal/alerts/pbs_datastore_override_alias_test.go b/internal/alerts/pbs_datastore_override_alias_test.go
index 667c9329e2..7e488ff52d 100644
--- a/internal/alerts/pbs_datastore_override_alias_test.go
+++ b/internal/alerts/pbs_datastore_override_alias_test.go
@@ -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},
diff --git a/internal/monitoring/monitor_alert_handling_test.go b/internal/monitoring/monitor_alert_handling_test.go
index a1c0c6e12f..d1d88aac64 100644
--- a/internal/monitoring/monitor_alert_handling_test.go
+++ b/internal/monitoring/monitor_alert_handling_test.go
@@ -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