From 5431ad2595178beeefa012e6a338c3e58ddbd630 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 1 Dec 2025 14:36:32 +0000 Subject: [PATCH] test: Add taskHeap.Less tiebreaker test case When tasks have identical NextRun and Priority, the Less function falls back to comparing InstanceName alphabetically. Add test to cover this edge case branch, improving Less coverage to 100%. --- internal/monitoring/task_queue_test.go | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/internal/monitoring/task_queue_test.go b/internal/monitoring/task_queue_test.go index cd9d73a..728d8b2 100644 --- a/internal/monitoring/task_queue_test.go +++ b/internal/monitoring/task_queue_test.go @@ -485,6 +485,51 @@ func TestTaskQueue_Upsert(t *testing.T) { verifyHeapInvariant(t, queue) }) + + t.Run("upsert with same time and priority - uses instance name for tiebreak", func(t *testing.T) { + queue := NewTaskQueue() + now := time.Now() + sameTime := now.Add(10 * time.Second) + + // Same NextRun, same priorities - should use InstanceName for tiebreak + tasks := []ScheduledTask{ + { + InstanceName: "pve-zebra", + InstanceType: InstanceTypePVE, + NextRun: sameTime, + Interval: 30 * time.Second, + Priority: 1.0, + }, + { + InstanceName: "pve-alpha", + InstanceType: InstanceTypePVE, + NextRun: sameTime, + Interval: 30 * time.Second, + Priority: 1.0, + }, + { + InstanceName: "pve-middle", + InstanceType: InstanceTypePVE, + NextRun: sameTime, + Interval: 30 * time.Second, + Priority: 1.0, + }, + } + + for _, task := range tasks { + queue.Upsert(task) + } + + // When NextRun and Priority are equal, alphabetically earlier name should be first + queue.mu.Lock() + root := queue.heap[0] + if root.task.InstanceName != "pve-alpha" { + t.Errorf("heap root = %s, want pve-alpha (alphabetically first when time and priority equal)", root.task.InstanceName) + } + queue.mu.Unlock() + + verifyHeapInvariant(t, queue) + }) } func TestTaskQueue_Remove(t *testing.T) {