From bd8e9dd021e38f858e0d34c7e2c3e35f6d643258 Mon Sep 17 00:00:00 2001 From: Kensei Nakada Date: Thu, 31 Oct 2024 09:14:29 +0900 Subject: [PATCH] fix: flake TestSchedulerScheduleOne --- pkg/scheduler/schedule_one_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/schedule_one_test.go b/pkg/scheduler/schedule_one_test.go index ecf96ecbfd6..6e628fa1b71 100644 --- a/pkg/scheduler/schedule_one_test.go +++ b/pkg/scheduler/schedule_one_test.go @@ -852,7 +852,11 @@ func TestSchedulerScheduleOne(t *testing.T) { if diff := cmp.Diff(item.expectBind, gotBinding); diff != "" { t.Errorf("got binding diff (-want, +got): %s", diff) } - if len(queue.InFlightPods()) != 0 { + // We have to use wait here + // because the Pod goes to the binding cycle in some test cases and the inflight pods might not be empty immediately at this point in such case. + if err := wait.PollUntilContextTimeout(ctx, time.Millisecond*200, wait.ForeverTestTimeout, false, func(ctx context.Context) (bool, error) { + return len(queue.InFlightPods()) == 0, nil + }); err != nil { t.Errorf("in-flight pods should be always empty after SchedulingOne. It has %v Pods", len(queue.InFlightPods())) } stopFunc()