Change:
<!-- Please only use this template for submitting enhancement requests --What would you like to be : Currently some unit tests in pkg/scheduler is not organized as Use subtests can make it easier to find out which case fails and leverage benefit of parallelism . Why is this needed: Follow Go test practice.
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the label and provide further guidance. The label can be by org members by writing in a comment. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/remove-kind feature /kind cleanup /sig scheduling /assign

Discussion:
} for _, test := range tests { <del> nodes := makeNodeList([]string{"1"}) </del> <ins> t.Run(test.name, func(t *testing.T) { nodes := makeNodeList([]string{"1"}) </ins> <del> plugin := st.FakeFilterPlugin{} registerFakeFilterFunc := st.RegisterFilterPlugin( "FakeFilter", func(_ runtime.Object, fh framework.Handle) (framework.Plugin, error) { return &plugin, nil }, ) registerPlugins := []st.RegisterPluginFunc{ st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), registerFakeFilterFunc, st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), } fwk, err := st.NewFramework( registerPlugins, frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { t.Fatal(err) } </del> <ins> plugin := st.FakeFilterPlugin{} registerFakeFilterFunc := st.RegisterFilterPlugin( "FakeFilter", func(_ runtime.Object, fh framework.Handle) (framework.Plugin, error) { return &plugin, nil }, ) registerPlugins := []st.RegisterPluginFunc{ st.RegisterQueueSortPlugin(queuesort.Name, queuesort.New), registerFakeFilterFunc, st.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New), } fwk, err := st.NewFramework( registerPlugins, frameworkruntime.WithPodNominator(internalqueue.NewPodNominator()), ) if err != nil { t.Fatal(err) } </ins> <del> scheduler := makeScheduler(nodes) if err := scheduler.cache.UpdateSnapshot(scheduler.nodeInfoSnapshot); err != nil { t.Fatal(err) } fwk.PreemptHandle().AddNominatedPod(&v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: "nominated"}, Spec: v1.PodSpec{Priority: &midPriority}}, "1") </del> <ins> scheduler := makeScheduler(nodes) if err := scheduler.cache.UpdateSnapshot(scheduler.nodeInfoSnapshot); err != nil { t.Fatal(err) } fwk.PreemptHandle().AddNominatedPod(&v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: "nominated"}, Spec: v1.PodSpec{Priority: &midPriority}}, "1") </ins> <del> _, _, err = scheduler.findNodesThatFitPod(context.Background(), fwk, framework.NewCycleState(), test.pod) </del> <ins> _, _, err = scheduler.findNodesThatFitPod(context.Background(), fwk, framework.NewCycleState(), test.pod) </ins> <del> if err != nil { t.Errorf("unexpected error: %v", err) } if test.expectedCount != plugin.NumFilterCalled { t.Errorf("predicate was called %d times, expected is %d", plugin.NumFilterCalled, test.expectedCount) } </del> <ins> if err != nil { t.Errorf("unexpected error: %v", err) } if test.expectedCount != plugin.NumFilterCalled { t.Errorf("predicate was called %d times, expected is %d", plugin.NumFilterCalled, test.expectedCount) } }) </ins> } }

podsToAdd:    []*v1.Pod{testPods[0]}, }} <del> for _, tt := range tests { cache := newSchedulerCache(ttl, time.Second, nil) for _, podToAssume := range tt.podsToAssume { if err := assumeAndFinishBinding(cache, podToAssume, now); err != nil { t.Errorf("assumePod failed: %v", err) </del> <ins> for i, tt := range tests { t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) { cache := newSchedulerCache(ttl, time.Second, nil) for _, podToAssume := range tt.podsToAssume { if err := assumeAndFinishBinding(cache, podToAssume, now); err != nil { t.Errorf("assumePod failed: %v", err) } </ins> } <del> } for _, podToAdd := range tt.podsToAdd { if err := cache.AddPod(podToAdd); err != nil { t.Errorf("AddPod failed: %v", err) </del> <ins> for _, podToAdd := range tt.podsToAdd { if err := cache.AddPod(podToAdd); err != nil { t.Errorf("AddPod failed: %v", err) } </ins> } <del> } snapshot := cache.Dump() if len(snapshot.Nodes) != len(cache.nodes) { t.Errorf("Unequal number of nodes in the cache and its snapshot. expected: %v, got: %v", len(cache.nodes), len(snapshot.Nodes)) } for name, ni := range snapshot.Nodes { nItem := cache.nodes[name] if !reflect.DeepEqual(ni, nItem.info) { t.Errorf("expect n%+v; got n%+v", nItem.info, ni) </del> <ins> snapshot := cache.Dump() if len(snapshot.Nodes) != len(cache.nodes) { t.Errorf("Unequal number of nodes in the cache and its snapshot. expected: %v, got: %v", len(cache.nodes), len(snapshot.Nodes)) </ins> } <del> } if !reflect.DeepEqual(snapshot.AssumedPods, cache.assumedPods) { t.Errorf("expect n%+v; got n%+v", cache.assumedPods, snapshot.AssumedPods) } </del> <ins> for name, ni := range snapshot.Nodes { nItem := cache.nodes[name] if !reflect.DeepEqual(ni, nItem.info) { t.Errorf("expect n%+v; got n%+v", nItem.info, ni) } } if !reflect.DeepEqual(snapshot.AssumedPods, cache.assumedPods) { t.Errorf("expect n%+v; got n%+v", cache.assumedPods, snapshot.AssumedPods) } }) </ins> } }

}, } <del> for _, tt := range tests { cache := newSchedulerCache(ttl, time.Second, nil) </del> <ins> for i, tt := range tests { t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) { cache := newSchedulerCache(ttl, time.Second, nil) </ins> <del> if err := tt.handler(cache, tt.pod); err != nil { t.Fatalf("unexpected err: %v", err) } </del> <ins> if err := tt.handler(cache, tt.pod); err != nil { t.Fatalf("unexpected err: %v", err) } </ins> <del> if !tt.assumePod { if err := cache.UpdatePod(tt.pod, tt.podToUpdate); err != nil { t.Fatalf("UpdatePod failed: %v", err) </del> <ins> if !tt.assumePod { if err := cache.UpdatePod(tt.pod, tt.podToUpdate); err != nil { t.Fatalf("UpdatePod failed: %v", err) } </ins> } <del> } cachedPod, err := cache.GetPod(tt.pod) if err != nil { t.Fatalf("GetPod failed: %v", err) } if !reflect.DeepEqual(tt.podToUpdate, cachedPod) { t.Fatalf("pod get=%s, want=%s", cachedPod, tt.podToUpdate) } </del> <ins> cachedPod, err := cache.GetPod(tt.pod) if err != nil { t.Fatalf("GetPod failed: %v", err) } if !reflect.DeepEqual(tt.podToUpdate, cachedPod) { t.Fatalf("pod get=%s, want=%s", cachedPod, tt.podToUpdate) } }) </ins> } }

package cache import ( <ins> "fmt" </ins> "reflect" "testing"

}, } <del> for _, test := range tests { imageStates := getNodeImageStates(test.node, test.imageExistenceMap) if !reflect.DeepEqual(test.expected, imageStates) { t.Errorf("expected: %#v, got: %#v", test.expected, imageStates) } </del> <ins> for i, test := range tests { t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) { imageStates := getNodeImageStates(test.node, test.imageExistenceMap) if !reflect.DeepEqual(test.expected, imageStates) { t.Errorf("expected: %#v, got: %#v", test.expected, imageStates) } }) </ins> } }

}, } <del> for _, test := range tests { imageMap := createImageExistenceMap(test.nodes) if !reflect.DeepEqual(test.expected, imageMap) { t.Errorf("expected: %#v, got: %#v", test.expected, imageMap) } </del> <ins> for i, test := range tests { t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) { imageMap := createImageExistenceMap(test.nodes) if !reflect.DeepEqual(test.expected, imageMap) { t.Errorf("expected: %#v, got: %#v", test.expected, imageMap) } }) </ins> } }

} for k, v := range tests { <del> got := MoreImportantPod(v.p1, v.p2) if got != v.expected { t.Errorf("%s failed, expected %t but got %t", k, v.expected, got) } </del> <ins> t.Run(k, func(t *testing.T) { got := MoreImportantPod(v.p1, v.p2) if got != v.expected { t.Errorf("expected %t but got %t", v.expected, got) } }) </ins> } }