Skip to content

Commit 471679f

Browse files
committed
fix the flake in scheduling_queue_test
1 parent 7a44964 commit 471679f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

pkg/scheduler/internal/queue/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ go_test(
2929
"//staging/src/k8s.io/api/core/v1:go_default_library",
3030
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
3131
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
32+
"//staging/src/k8s.io/apimachinery/pkg/util/clock:go_default_library",
3233
],
3334
)
3435

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"
29+
"k8s.io/apimachinery/pkg/util/clock"
2930
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3031
"k8s.io/kubernetes/pkg/scheduler/util"
3132
)
@@ -98,7 +99,7 @@ var highPriorityPod, highPriNominatedPod, medPriorityPod, unschedulablePod = v1.
9899
func addOrUpdateUnschedulablePod(p *PriorityQueue, pod *v1.Pod) {
99100
p.lock.Lock()
100101
defer p.lock.Unlock()
101-
p.unschedulableQ.addOrUpdate(newPodInfoNoTimestamp(pod))
102+
p.unschedulableQ.addOrUpdate(p.newPodInfo(pod))
102103
}
103104

104105
func getUnschedulablePod(p *PriorityQueue, pod *v1.Pod) *v1.Pod {
@@ -983,8 +984,8 @@ func TestHighProirotyFlushUnschedulableQLeftover(t *testing.T) {
983984
Message: "fake scheduling failure",
984985
})
985986

986-
q.unschedulableQ.addOrUpdate(newPodInfoNoTimestamp(&highPod))
987-
q.unschedulableQ.addOrUpdate(newPodInfoNoTimestamp(&midPod))
987+
addOrUpdateUnschedulablePod(q, &highPod)
988+
addOrUpdateUnschedulablePod(q, &midPod)
988989
q.unschedulableQ.podInfoMap[util.GetPodFullName(&highPod)].timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
989990
q.unschedulableQ.podInfoMap[util.GetPodFullName(&midPod)].timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
990991

@@ -1020,13 +1021,14 @@ func TestPodTimestamp(t *testing.T) {
10201021
},
10211022
}
10221023

1024+
var timestamp = time.Now()
10231025
pInfo1 := &podInfo{
10241026
pod: pod1,
1025-
timestamp: util.RealClock{}.Now(),
1027+
timestamp: timestamp,
10261028
}
10271029
pInfo2 := &podInfo{
10281030
pod: pod2,
1029-
timestamp: util.RealClock{}.Now().Add(1 * time.Second),
1031+
timestamp: timestamp.Add(time.Second),
10301032
}
10311033

10321034
var queue *PriorityQueue
@@ -1071,8 +1073,14 @@ func TestPodTimestamp(t *testing.T) {
10711073
queue.MoveAllToActiveQueue()
10721074
}
10731075
}
1076+
backoffPod := func(pInfo *podInfo) operation {
1077+
return func() {
1078+
queue.backoffPod(pInfo.pod)
1079+
}
1080+
}
10741081
flushBackoffQ := func() operation {
10751082
return func() {
1083+
queue.clock.(*clock.FakeClock).Step(2 * time.Second)
10761084
queue.flushBackoffQCompleted()
10771085
}
10781086
}
@@ -1105,15 +1113,15 @@ func TestPodTimestamp(t *testing.T) {
11051113
{
11061114
name: "add one pod to BackoffQ and move it to activeQ",
11071115
operations: []operation{
1108-
addPodActiveQ(pInfo2), addPodBackoffQ(pInfo1), flushBackoffQ(), moveAllToActiveQ(),
1116+
addPodActiveQ(pInfo2), addPodBackoffQ(pInfo1), backoffPod(pInfo1), flushBackoffQ(), moveAllToActiveQ(),
11091117
},
11101118
expected: []*podInfo{pInfo1, pInfo2},
11111119
},
11121120
}
11131121

11141122
for _, test := range tests {
11151123
t.Run(test.name, func(t *testing.T) {
1116-
queue = NewPriorityQueue(nil)
1124+
queue = NewPriorityQueueWithClock(nil, clock.NewFakeClock(timestamp))
11171125
var podInfoList []*podInfo
11181126

11191127
for _, op := range test.operations {

0 commit comments

Comments
 (0)