Skip to content

Commit f6d05d6

Browse files
authored
Merge pull request kubernetes#74611 from denkensk/fix-unable-find-backoff-value
fix the flake in scheduling_queue_test
2 parents ae56122 + 471679f commit f6d05d6

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 {
@@ -973,8 +974,8 @@ func TestHighProirotyFlushUnschedulableQLeftover(t *testing.T) {
973974
Message: "fake scheduling failure",
974975
})
975976

976-
q.unschedulableQ.addOrUpdate(newPodInfoNoTimestamp(&highPod))
977-
q.unschedulableQ.addOrUpdate(newPodInfoNoTimestamp(&midPod))
977+
addOrUpdateUnschedulablePod(q, &highPod)
978+
addOrUpdateUnschedulablePod(q, &midPod)
978979
q.unschedulableQ.podInfoMap[util.GetPodFullName(&highPod)].timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
979980
q.unschedulableQ.podInfoMap[util.GetPodFullName(&midPod)].timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
980981

@@ -1010,13 +1011,14 @@ func TestPodTimestamp(t *testing.T) {
10101011
},
10111012
}
10121013

1014+
var timestamp = time.Now()
10131015
pInfo1 := &podInfo{
10141016
pod: pod1,
1015-
timestamp: util.RealClock{}.Now(),
1017+
timestamp: timestamp,
10161018
}
10171019
pInfo2 := &podInfo{
10181020
pod: pod2,
1019-
timestamp: util.RealClock{}.Now().Add(1 * time.Second),
1021+
timestamp: timestamp.Add(time.Second),
10201022
}
10211023

10221024
var queue *PriorityQueue
@@ -1061,8 +1063,14 @@ func TestPodTimestamp(t *testing.T) {
10611063
queue.MoveAllToActiveQueue()
10621064
}
10631065
}
1066+
backoffPod := func(pInfo *podInfo) operation {
1067+
return func() {
1068+
queue.backoffPod(pInfo.pod)
1069+
}
1070+
}
10641071
flushBackoffQ := func() operation {
10651072
return func() {
1073+
queue.clock.(*clock.FakeClock).Step(2 * time.Second)
10661074
queue.flushBackoffQCompleted()
10671075
}
10681076
}
@@ -1095,15 +1103,15 @@ func TestPodTimestamp(t *testing.T) {
10951103
{
10961104
name: "add one pod to BackoffQ and move it to activeQ",
10971105
operations: []operation{
1098-
addPodActiveQ(pInfo2), addPodBackoffQ(pInfo1), flushBackoffQ(), moveAllToActiveQ(),
1106+
addPodActiveQ(pInfo2), addPodBackoffQ(pInfo1), backoffPod(pInfo1), flushBackoffQ(), moveAllToActiveQ(),
10991107
},
11001108
expected: []*podInfo{pInfo1, pInfo2},
11011109
},
11021110
}
11031111

11041112
for _, test := range tests {
11051113
t.Run(test.name, func(t *testing.T) {
1106-
queue = NewPriorityQueue(nil)
1114+
queue = NewPriorityQueueWithClock(nil, clock.NewFakeClock(timestamp))
11071115
var podInfoList []*podInfo
11081116

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

0 commit comments

Comments
 (0)