Revert "Fix flaky test on multi profiles waiting pod"

This reverts commit 5b072a59a2.
This commit is contained in:
kerthcet 2024-03-19 22:52:07 +01:00
parent fe9e4698a3
commit a67d1dc010

View File

@ -31,7 +31,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
@ -995,7 +994,6 @@ func TestFrameworkHandler_IterateOverWaitingPods(t *testing.T) {
fakeClient := fake.NewSimpleClientset(objs...) fakeClient := fake.NewSimpleClientset(objs...)
informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) informerFactory := informers.NewSharedInformerFactory(fakeClient, 0)
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: fakeClient.EventsV1()}) eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: fakeClient.EventsV1()})
defer eventBroadcaster.Shutdown()
eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, fakePermit) eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, fakePermit)
outOfTreeRegistry := frameworkruntime.Registry{ outOfTreeRegistry := frameworkruntime.Registry{
@ -1003,8 +1001,7 @@ func TestFrameworkHandler_IterateOverWaitingPods(t *testing.T) {
} }
_, ctx := ktesting.NewTestContext(t) _, ctx := ktesting.NewTestContext(t)
// timeout equals to the permit plugin waiting time. ctx, cancel := context.WithCancel(ctx)
ctx, cancel := context.WithTimeout(ctx, 100*time.Second)
defer cancel() defer cancel()
scheduler, err := New( scheduler, err := New(
@ -1052,23 +1049,17 @@ func TestFrameworkHandler_IterateOverWaitingPods(t *testing.T) {
// Wait all pods in waitSchedulingPods to be scheduled. // Wait all pods in waitSchedulingPods to be scheduled.
wg.Wait() wg.Wait()
// When permit plugin emits the event, pod may not been added to the waitingPods pool yet, so we use pollUntil here. // Ensure that all waitingPods in scheduler can be obtained from any profiles.
if err := wait.PollUntilContextCancel(ctx, 100*time.Microsecond, true, func(context.Context) (done bool, err error) { for _, fwk := range scheduler.Profiles {
// Ensure that all waitingPods in scheduler can be obtained from any profiles. actualPodNamesInWaitingPods := sets.NewString()
for _, fwk := range scheduler.Profiles { fwk.IterateOverWaitingPods(func(pod framework.WaitingPod) {
actualPodNamesInWaitingPods := sets.NewString() actualPodNamesInWaitingPods.Insert(pod.GetPod().Name)
fwk.IterateOverWaitingPods(func(pod framework.WaitingPod) { })
actualPodNamesInWaitingPods.Insert(pod.GetPod().Name) // Validate the name of pods in waitingPods matches expectations.
}) if actualPodNamesInWaitingPods.Len() != len(tc.expectPodNamesInWaitingPods) ||
// Validate the name of pods in waitingPods matches expectations. !actualPodNamesInWaitingPods.HasAll(tc.expectPodNamesInWaitingPods...) {
if actualPodNamesInWaitingPods.Len() != len(tc.expectPodNamesInWaitingPods) || t.Fatalf("Unexpected waitingPods in scheduler profile %s, expect: %#v, got: %#v", fwk.ProfileName(), tc.expectPodNamesInWaitingPods, actualPodNamesInWaitingPods.List())
!actualPodNamesInWaitingPods.HasAll(tc.expectPodNamesInWaitingPods...) {
return false, fmt.Errorf("Unexpected waitingPods in scheduler profile %s, expect: %#v, got: %#v", fwk.ProfileName(), tc.expectPodNamesInWaitingPods, actualPodNamesInWaitingPods.List())
}
} }
return true, nil
}); err != nil {
t.Fatal("got unexpected result")
} }
}) })
} }