Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec0739b

Browse files
committed
Fix races in scheduling queue tests
1 parent f7c4389 commit ec0739b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -443,18 +443,26 @@ func TestPriorityQueue_NominatedPodsForNode(t *testing.T) {
443443
}
444444

445445
func TestPriorityQueue_PendingPods(t *testing.T) {
446+
makeSet := func(pods []*v1.Pod) map[*v1.Pod]struct{} {
447+
pendingSet := map[*v1.Pod]struct{}{}
448+
for _, p := range pods {
449+
pendingSet[p] = struct{}{}
450+
}
451+
return pendingSet
452+
}
453+
446454
q := NewPriorityQueue(nil)
447455
q.Add(&medPriorityPod)
448456
addOrUpdateUnschedulablePod(q, &unschedulablePod)
449457
addOrUpdateUnschedulablePod(q, &highPriorityPod)
450-
expectedList := []*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod}
451-
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
452-
t.Error("Unexpected list of pending Pods for node.")
458+
expectedSet := makeSet([]*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod})
459+
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
460+
t.Error("Unexpected list of pending Pods.")
453461
}
454462
// Move all to active queue. We should still see the same set of pods.
455463
q.MoveAllToActiveQueue()
456-
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
457-
t.Error("Unexpected list of pending Pods for node.")
464+
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
465+
t.Error("Unexpected list of pending Pods...")
458466
}
459467
}
460468

@@ -954,8 +962,8 @@ func TestHighProirotyFlushUnschedulableQLeftover(t *testing.T) {
954962
},
955963
}
956964

957-
q.unschedulableQ.addOrUpdate(&highPod)
958-
q.unschedulableQ.addOrUpdate(&midPod)
965+
addOrUpdateUnschedulablePod(q, &highPod)
966+
addOrUpdateUnschedulablePod(q, &midPod)
959967

960968
// Update pod condition to highPod.
961969
podutil.UpdatePodCondition(&highPod.Status, &v1.PodCondition{

0 commit comments

Comments
 (0)