Merge pull request #123686 from kerthcet/fix/flaky-test-on-multi-profile

[Scheduler] Fix flaky test on multi profiles waitingPods
This commit is contained in:
Kubernetes Prow Robot 2024-03-05 04:41:09 -08:00 committed by GitHub
commit 13f40e9759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,7 @@ 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"
@ -977,6 +978,7 @@ 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{
@ -984,7 +986,8 @@ func TestFrameworkHandler_IterateOverWaitingPods(t *testing.T) {
} }
_, ctx := ktesting.NewTestContext(t) _, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx) // timeout equals to the permit plugin waiting time.
ctx, cancel := context.WithTimeout(ctx, 100*time.Second)
defer cancel() defer cancel()
scheduler, err := New( scheduler, err := New(
@ -1032,17 +1035,23 @@ 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()
// Ensure that all waitingPods in scheduler can be obtained from any profiles. // When permit plugin emits the event, pod may not been added to the waitingPods pool yet, so we use pollUntil here.
for _, fwk := range scheduler.Profiles { if err := wait.PollUntilContextCancel(ctx, 100*time.Microsecond, true, func(context.Context) (done bool, err error) {
actualPodNamesInWaitingPods := sets.NewString() // Ensure that all waitingPods in scheduler can be obtained from any profiles.
fwk.IterateOverWaitingPods(func(pod framework.WaitingPod) { for _, fwk := range scheduler.Profiles {
actualPodNamesInWaitingPods.Insert(pod.GetPod().Name) actualPodNamesInWaitingPods := sets.NewString()
}) fwk.IterateOverWaitingPods(func(pod framework.WaitingPod) {
// Validate the name of pods in waitingPods matches expectations. actualPodNamesInWaitingPods.Insert(pod.GetPod().Name)
if actualPodNamesInWaitingPods.Len() != len(tc.expectPodNamesInWaitingPods) || })
!actualPodNamesInWaitingPods.HasAll(tc.expectPodNamesInWaitingPods...) { // Validate the name of pods in waitingPods matches expectations.
t.Fatalf("Unexpected waitingPods in scheduler profile %s, expect: %#v, got: %#v", fwk.ProfileName(), tc.expectPodNamesInWaitingPods, actualPodNamesInWaitingPods.List()) if actualPodNamesInWaitingPods.Len() != len(tc.expectPodNamesInWaitingPods) ||
!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")
} }
}) })
} }