From 4b2c054e598e7118e8c59fe6c2b2b1cf34dbc0b8 Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Wed, 2 Sep 2020 13:28:45 +0800 Subject: [PATCH] Enhancement on the testcase to cover more possibilities This change enriches the testcase of `TestPriorityQueue_MoveAllToActiveOrBackoffQueue` to cover the case that pods in the unschedulableQ could be moved to activeQ after the backing off. Signed-off-by: Dave Chen --- .../internal/queue/scheduling_queue_test.go | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index 50304307365..597bce881fe 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -359,17 +359,41 @@ func TestPriorityQueue_Delete(t *testing.T) { } func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) { - q := NewPriorityQueue(newDefaultQueueSort()) + c := clock.NewFakeClock(time.Now()) + q := NewPriorityQueue(newDefaultQueueSort(), WithClock(c)) q.Add(&medPriorityPod) q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(&unschedulablePod), q.SchedulingCycle()) q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(&highPriorityPod), q.SchedulingCycle()) + // Pods is still backing off, move the pod into backoffQ. q.MoveAllToActiveOrBackoffQueue("test") if q.activeQ.Len() != 1 { - t.Error("Expected 1 item to be in activeQ") + t.Errorf("Expected 1 item to be in activeQ, but got: %v", q.activeQ.Len()) } if q.podBackoffQ.Len() != 2 { - t.Error("Expected 2 items to be in podBackoffQ") + t.Errorf("Expected 2 items to be in podBackoffQ, but got: %v", q.podBackoffQ.Len()) } + + // pop out the pods in the backoffQ. + q.podBackoffQ.Pop() + q.podBackoffQ.Pop() + + q.schedulingCycle++ + q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(&unschedulablePod), q.SchedulingCycle()) + q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(&highPriorityPod), q.SchedulingCycle()) + if q.unschedulableQ.get(&unschedulablePod) == nil || q.unschedulableQ.get(&highPriorityPod) == nil { + t.Errorf("Expected %v and %v in the unschedulableQ", unschedulablePod.Name, highPriorityPod.Name) + } + // Move clock by podInitialBackoffDuration, so that pods in the unschedulableQ would pass the backing off, + // and the pods will be moved into activeQ. + c.Step(q.podInitialBackoffDuration) + q.MoveAllToActiveOrBackoffQueue("test") + if q.activeQ.Len() != 3 { + t.Errorf("Expected 3 items to be in activeQ, but got: %v", q.activeQ.Len()) + } + if q.podBackoffQ.Len() != 0 { + t.Errorf("Expected 0 item to be in podBackoffQ, but got: %v", q.podBackoffQ.Len()) + } + } // TestPriorityQueue_AssignedPodAdded tests AssignedPodAdded. It checks that