Merge pull request #91874 from gaurav1086/TestSchedulingQueue_Close_fix_race_condition

TestSchedulingQueue: Remove the unnecessary slice and for loop
This commit is contained in:
Kubernetes Prow Robot 2020-06-11 23:45:55 -07:00 committed by GitHub
commit b8f24173da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -710,35 +710,22 @@ func TestUnschedulablePodsMap(t *testing.T) {
} }
func TestSchedulingQueue_Close(t *testing.T) { func TestSchedulingQueue_Close(t *testing.T) {
tests := []struct { q := NewPriorityQueue(newDefaultQueueSort())
name string wantErr := fmt.Errorf(queueClosed)
q SchedulingQueue wg := sync.WaitGroup{}
expectedErr error wg.Add(1)
}{ go func() {
{ defer wg.Done()
name: "PriorityQueue close", pod, err := q.Pop()
q: NewPriorityQueue(newDefaultQueueSort()), if err.Error() != wantErr.Error() {
expectedErr: fmt.Errorf(queueClosed), t.Errorf("Expected err %q from Pop() if queue is closed, but got %q", wantErr.Error(), err.Error())
}, }
} if pod != nil {
for _, test := range tests { t.Errorf("Expected pod nil from Pop() if queue is closed, but got: %v", pod)
t.Run(test.name, func(t *testing.T) { }
wg := sync.WaitGroup{} }()
wg.Add(1) q.Close()
go func() { wg.Wait()
defer wg.Done()
pod, err := test.q.Pop()
if err.Error() != test.expectedErr.Error() {
t.Errorf("Expected err %q from Pop() if queue is closed, but got %q", test.expectedErr.Error(), err.Error())
}
if pod != nil {
t.Errorf("Expected pod nil from Pop() if queue is closed, but got: %v", pod)
}
}()
test.q.Close()
wg.Wait()
})
}
} }
// TestRecentlyTriedPodsGoBack tests that pods which are recently tried and are // TestRecentlyTriedPodsGoBack tests that pods which are recently tried and are