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%.
This commit is contained in:
rcourtman 2025-12-01 14:36:32 +00:00
parent e57e2e696b
commit b1ed1a2802

View file

@ -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) {