Skip to content

Commit b8f2417

Browse files
authored
Merge pull request kubernetes#91874 from gaurav1086/TestSchedulingQueue_Close_fix_race_condition
TestSchedulingQueue: Remove the unnecessary slice and for loop
2 parents bc9c5af + 00f2874 commit b8f2417

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -710,35 +710,22 @@ func TestUnschedulablePodsMap(t *testing.T) {
710710
}
711711

712712
func TestSchedulingQueue_Close(t *testing.T) {
713-
tests := []struct {
714-
name string
715-
q SchedulingQueue
716-
expectedErr error
717-
}{
718-
{
719-
name: "PriorityQueue close",
720-
q: NewPriorityQueue(newDefaultQueueSort()),
721-
expectedErr: fmt.Errorf(queueClosed),
722-
},
723-
}
724-
for _, test := range tests {
725-
t.Run(test.name, func(t *testing.T) {
726-
wg := sync.WaitGroup{}
727-
wg.Add(1)
728-
go func() {
729-
defer wg.Done()
730-
pod, err := test.q.Pop()
731-
if err.Error() != test.expectedErr.Error() {
732-
t.Errorf("Expected err %q from Pop() if queue is closed, but got %q", test.expectedErr.Error(), err.Error())
733-
}
734-
if pod != nil {
735-
t.Errorf("Expected pod nil from Pop() if queue is closed, but got: %v", pod)
736-
}
737-
}()
738-
test.q.Close()
739-
wg.Wait()
740-
})
741-
}
713+
q := NewPriorityQueue(newDefaultQueueSort())
714+
wantErr := fmt.Errorf(queueClosed)
715+
wg := sync.WaitGroup{}
716+
wg.Add(1)
717+
go func() {
718+
defer wg.Done()
719+
pod, err := q.Pop()
720+
if err.Error() != wantErr.Error() {
721+
t.Errorf("Expected err %q from Pop() if queue is closed, but got %q", wantErr.Error(), err.Error())
722+
}
723+
if pod != nil {
724+
t.Errorf("Expected pod nil from Pop() if queue is closed, but got: %v", pod)
725+
}
726+
}()
727+
q.Close()
728+
wg.Wait()
742729
}
743730

744731
// TestRecentlyTriedPodsGoBack tests that pods which are recently tried and are

0 commit comments

Comments
 (0)