Merge pull request #73943 from bsalamat/fix_race

Fix races in scheduling queue tests
This commit is contained in:
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

View File

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