Merge pull request #73943 from bsalamat/fix_race

Fix races in scheduling queue tests
pull/564/head
Kubernetes Prow Robot 2019-02-12 05:21:50 -08:00 committed by GitHub
commit ace0bde081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -443,18 +443,26 @@ func TestPriorityQueue_NominatedPodsForNode(t *testing.T) {
}
func TestPriorityQueue_PendingPods(t *testing.T) {
makeSet := func(pods []*v1.Pod) map[*v1.Pod]struct{} {
pendingSet := map[*v1.Pod]struct{}{}
for _, p := range pods {
pendingSet[p] = struct{}{}
}
return pendingSet
}
q := NewPriorityQueue(nil)
q.Add(&medPriorityPod)
addOrUpdateUnschedulablePod(q, &unschedulablePod)
addOrUpdateUnschedulablePod(q, &highPriorityPod)
expectedList := []*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod}
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
t.Error("Unexpected list of pending Pods for node.")
expectedSet := makeSet([]*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod})
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
t.Error("Unexpected list of pending Pods.")
}
// Move all to active queue. We should still see the same set of pods.
q.MoveAllToActiveQueue()
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
t.Error("Unexpected list of pending Pods for node.")
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
t.Error("Unexpected list of pending Pods...")
}
}
@ -954,8 +962,8 @@ func TestHighProirotyFlushUnschedulableQLeftover(t *testing.T) {
},
}
q.unschedulableQ.addOrUpdate(&highPod)
q.unschedulableQ.addOrUpdate(&midPod)
addOrUpdateUnschedulablePod(q, &highPod)
addOrUpdateUnschedulablePod(q, &midPod)
// Update pod condition to highPod.
podutil.UpdatePodCondition(&highPod.Status, &v1.PodCondition{