Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix: Race condition in TestLoadActiveAlerts causing flaky test

rcourtmanc5ab0724f1d8
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index 3bcbedc40a..6f8dde9c26 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -14688,7 +14688,6 @@ func TestLoadActiveAlerts(t *testing.T) {
t.Run("loads alerts from valid file", func(t *testing.T) {
m := newTestManager(t)
- m.ClearActiveAlerts()
// Create an alert and save it
startTime := time.Now().Add(-30 * time.Minute)
@@ -14714,8 +14713,10 @@ func TestLoadActiveAlerts(t *testing.T) {
// Save to disk
_ = m.SaveActiveAlerts()
- // Clear and reload
- m.ClearActiveAlerts()
+ // Clear in-memory map only (don't use ClearActiveAlerts which triggers async save)
+ m.mu.Lock()
+ m.activeAlerts = make(map[string]*Alert)
+ m.mu.Unlock()
err := m.LoadActiveAlerts()
if err != nil {
@@ -14739,7 +14740,6 @@ func TestLoadActiveAlerts(t *testing.T) {
t.Run("skips old alerts", func(t *testing.T) {
m := newTestManager(t)
- m.ClearActiveAlerts()
// Create an old alert (>24 hours)
startTime := time.Now().Add(-25 * time.Hour)
@@ -14760,8 +14760,10 @@ func TestLoadActiveAlerts(t *testing.T) {
// Save to disk
_ = m.SaveActiveAlerts()
- // Clear and reload
- m.ClearActiveAlerts()
+ // Clear in-memory map only (don't use ClearActiveAlerts which triggers async save)
+ m.mu.Lock()
+ m.activeAlerts = make(map[string]*Alert)
+ m.mu.Unlock()
err := m.LoadActiveAlerts()
if err != nil {
@@ -14779,7 +14781,6 @@ func TestLoadActiveAlerts(t *testing.T) {
t.Run("skips old acknowledged alerts", func(t *testing.T) {
m := newTestManager(t)
- m.ClearActiveAlerts()
// Create an alert acknowledged >1 hour ago
startTime := time.Now().Add(-30 * time.Minute)
@@ -14804,8 +14805,10 @@ func TestLoadActiveAlerts(t *testing.T) {
// Save to disk
_ = m.SaveActiveAlerts()
- // Clear and reload
- m.ClearActiveAlerts()
+ // Clear in-memory map only (don't use ClearActiveAlerts which triggers async save)
+ m.mu.Lock()
+ m.activeAlerts = make(map[string]*Alert)
+ m.mu.Unlock()
err := m.LoadActiveAlerts()
if err != nil {
@@ -14823,7 +14826,6 @@ func TestLoadActiveAlerts(t *testing.T) {
t.Run("restores acknowledgment state", func(t *testing.T) {
m := newTestManager(t)
- m.ClearActiveAlerts()
// Create an acknowledged alert
startTime := time.Now().Add(-10 * time.Minute)
@@ -14848,8 +14850,11 @@ func TestLoadActiveAlerts(t *testing.T) {
// Save to disk
_ = m.SaveActiveAlerts()
- // Clear and reload
- m.ClearActiveAlerts()
+ // Clear in-memory maps only (don't use ClearActiveAlerts which triggers async save)
+ m.mu.Lock()
+ m.activeAlerts = make(map[string]*Alert)
+ m.ackState = make(map[string]ackRecord)
+ m.mu.Unlock()
err := m.LoadActiveAlerts()
if err != nil {