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.

test: Add DispatchDue enqueue error test for monitoring package

rcourtman049d6946ae8d
diff --git a/internal/monitoring/scheduler_test.go b/internal/monitoring/scheduler_test.go
index 7c625cdc67..e79a2dfce1 100644
--- a/internal/monitoring/scheduler_test.go
+++ b/internal/monitoring/scheduler_test.go
@@ -2,6 +2,7 @@ package monitoring
import (
"context"
+ "errors"
"math/rand"
"testing"
"time"
@@ -2225,6 +2226,35 @@ func TestDispatchDue_NoDueTasks(t *testing.T) {
}
}
+// mockFailingEnqueuer is a test enqueuer that always returns an error
+type mockFailingEnqueuer struct{}
+
+func (m *mockFailingEnqueuer) Enqueue(ctx context.Context, task ScheduledTask) error {
+ return errors.New("enqueue failed")
+}
+
+// TestDispatchDue_EnqueueError tests DispatchDue when enqueue returns an error
+func TestDispatchDue_EnqueueError(t *testing.T) {
+ t.Parallel()
+
+ enqueuer := &mockFailingEnqueuer{}
+ cfg := DefaultSchedulerConfig()
+ scheduler := NewAdaptiveScheduler(cfg, nil, nil, enqueuer)
+
+ now := time.Now()
+ tasks := []ScheduledTask{
+ {InstanceName: "pve1", NextRun: now.Add(-1 * time.Second)},
+ {InstanceName: "pve2", NextRun: now.Add(-2 * time.Second)},
+ }
+
+ // Should still return due tasks even if enqueue fails
+ due := scheduler.DispatchDue(context.Background(), now, tasks)
+
+ if len(due) != 2 {
+ t.Fatalf("expected 2 due tasks returned even with enqueue error, got %d", len(due))
+ }
+}
+
// TestLastScheduled_NilScheduler tests LastScheduled with nil scheduler
func TestLastScheduled_NilScheduler(t *testing.T) {
t.Parallel()