Change:
/kind failing-test /kind flake First seen in an unrelated PR, but also occurs in periodic jobs. /sig scheduling
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
/assign This feature is reverted once, and I fixed the flake, I'm cherry-pick that back again.

Discussion:
"time" "github.com/google/go-cmp/cmp" <ins> "github.com/onsi/gomega" </ins> v1 "k8s.io/api/core/v1" eventsv1 "k8s.io/api/events/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

featuregatetesting "k8s.io/component-base/featuregate/testing" "k8s.io/klog/v2" "k8s.io/klog/v2/ktesting" <ins> testingclock "k8s.io/utils/clock/testing" "k8s.io/utils/ptr" </ins> "k8s.io/kubernetes/pkg/features" schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/apis/config/testing/defaults"

"k8s.io/kubernetes/pkg/scheduler/profile" st "k8s.io/kubernetes/pkg/scheduler/testing" tf "k8s.io/kubernetes/pkg/scheduler/testing/framework" <del> testingclock "k8s.io/utils/clock/testing" "k8s.io/utils/ptr" </del> <ins> utiltesting "k8s.io/kubernetes/test/utils/ktesting" </ins> ) func TestSchedulerCreation(t *testing.T) {

fakeClient := fake.NewSimpleClientset(objs...) informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: fakeClient.EventsV1()}) <ins> defer eventBroadcaster.Shutdown() </ins> eventRecorder := eventBroadcaster.NewRecorder(scheme.Scheme, fakePermit) outOfTreeRegistry := frameworkruntime.Registry{ fakePermit: newFakePermitPlugin(eventRecorder), } <del> _, ctx := ktesting.NewTestContext(t) ctx, cancel := context.WithCancel(ctx) defer cancel() </del> <ins> tCtx := utiltesting.Init(t) </ins> scheduler, err := New( <del> ctx, </del> <ins> tCtx, </ins> fakeClient, informerFactory, nil,

defer stopFn() // Run scheduler. <del> informerFactory.Start(ctx.Done()) informerFactory.WaitForCacheSync(ctx.Done()) go scheduler.Run(ctx) </del> <ins> informerFactory.Start(tCtx.Done()) informerFactory.WaitForCacheSync(tCtx.Done()) go scheduler.Run(tCtx) </ins> // Send pods to be scheduled. for _, p := range tc.waitSchedulingPods { <del> _, err = fakeClient.CoreV1().Pods("").Create(ctx, p, metav1.CreateOptions{}) </del> <ins> _, err = fakeClient.CoreV1().Pods("").Create(tCtx, p, metav1.CreateOptions{}) </ins> if err != nil { t.Fatal(err) }

// Wait all pods in waitSchedulingPods to be scheduled. wg.Wait() <del> // Ensure that all waitingPods in scheduler can be obtained from any profiles. for _, fwk := range scheduler.Profiles { actualPodNamesInWaitingPods := sets.NewString() 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) || !actualPodNamesInWaitingPods.HasAll(tc.expectPodNamesInWaitingPods...) { t.Fatalf("Unexpected waitingPods in scheduler profile %s, expect: %#v, got: %#v", fwk.ProfileName(), tc.expectPodNamesInWaitingPods, actualPodNamesInWaitingPods.List()) </del> <ins> utiltesting.Eventually(tCtx, func(utiltesting.TContext) sets.Set[string] { // Ensure that all waitingPods in scheduler can be obtained from any profiles. actualPodNamesInWaitingPods := sets.New[string]() for _, fwk := range scheduler.Profiles { fwk.IterateOverWaitingPods(func(pod framework.WaitingPod) { actualPodNamesInWaitingPods.Insert(pod.GetPod().Name) }) </ins> } <del> } </del> <ins> return actualPodNamesInWaitingPods }).WithTimeout(permitTimeout).Should(gomega.Equal(sets.New(tc.expectPodNamesInWaitingPods...)), "unexpected waitingPods in scheduler profile") </ins> }) } }

const ( podWaitingReason = "podWaiting" <ins> permitTimeout    = 10 * time.Second </ins> ) func (f fakePermitPlugin) Permit(ctx context.Context, state *framework.CycleState, p *v1.Pod, nodeName string) (*framework.Status, time.Duration) {

f.eventRecorder.Eventf(p, nil, v1.EventTypeWarning, podWaitingReason, "", "") }() <del> return framework.NewStatus(framework.Wait), 100 * time.Second </del> <ins> return framework.NewStatus(framework.Wait), permitTimeout </ins> } var _ framework.PermitPlugin = &fakePermitPlugin{}