Passed context for Wait methods in integration test utils

This commit is contained in:
Sharath P J 2025-01-24 19:47:02 +05:30
parent 2d32348f86
commit 627e83c841
8 changed files with 68 additions and 69 deletions

View File

@ -131,7 +131,7 @@ func TestUpdateNodeEvent(t *testing.T) {
t.Fatalf("Error updating the node: %v", err) t.Fatalf("Error updating the node: %v", err)
} }
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Pod %v was not scheduled: %v", pod.Name, err) t.Errorf("Pod %v was not scheduled: %v", pod.Name, err)
} }
} }

View File

@ -2165,7 +2165,7 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
if err := tt.update(testCtx.ClientSet, testCtx.NS.Name); err != nil { if err := tt.update(testCtx.ClientSet, testCtx.NS.Name); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Pod %v was not scheduled: %v", pod.Name, err) t.Errorf("Pod %v was not scheduled: %v", pod.Name, err)
} }
// Make sure pending queue is empty. // Make sure pending queue is empty.

View File

@ -693,7 +693,7 @@ func TestPreFilterPlugin(t *testing.T) {
t.Errorf("Expected a scheduling error, but got: %v", err) t.Errorf("Expected a scheduling error, but got: %v", err)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
} }
@ -873,7 +873,7 @@ func TestPostFilterPlugin(t *testing.T) {
t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
if numFilterCalled := filterPlugin.deepCopy().numFilterCalled; numFilterCalled != tt.expectFilterNumCalled { if numFilterCalled := filterPlugin.deepCopy().numFilterCalled; numFilterCalled != tt.expectFilterNumCalled {
@ -935,7 +935,7 @@ func TestScorePlugin(t *testing.T) {
t.Errorf("Expected a scheduling error, but got: %v", err) t.Errorf("Expected a scheduling error, but got: %v", err)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} else { } else {
p, err := testutils.GetPod(testCtx.ClientSet, pod.Name, pod.Namespace) p, err := testutils.GetPod(testCtx.ClientSet, pod.Name, pod.Namespace)
@ -971,7 +971,7 @@ func TestNormalizeScorePlugin(t *testing.T) {
t.Fatalf("Error while creating a test pod: %v", err) t.Fatalf("Error while creating a test pod: %v", err)
} }
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1027,7 +1027,7 @@ func TestReservePluginReserve(t *testing.T) {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
} }
@ -1147,7 +1147,7 @@ func TestPrebindPlugin(t *testing.T) {
if test.fail { if test.fail {
if test.succeedOnRetry { if test.succeedOnRetry {
if err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod, 10*time.Second); err != nil { if err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod, 10*time.Second); err != nil {
t.Errorf("Expected the pod to be schedulable on retry, but got an error: %v", err) t.Errorf("Expected the pod to be schedulable on retry, but got an error: %v", err)
} }
} else if err = wait.PollUntilContextTimeout(testCtx.Ctx, 10*time.Millisecond, 30*time.Second, false, } else if err = wait.PollUntilContextTimeout(testCtx.Ctx, 10*time.Millisecond, 30*time.Second, false,
@ -1158,7 +1158,7 @@ func TestPrebindPlugin(t *testing.T) {
if err = testutils.WaitForPodUnschedulable(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodUnschedulable(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be unschedulable") t.Errorf("Expected the pod to be unschedulable")
} }
} else if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { } else if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1314,7 +1314,7 @@ func TestUnReserveReservePlugins(t *testing.T) {
} }
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1396,7 +1396,7 @@ func TestUnReservePermitPlugins(t *testing.T) {
t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1468,7 +1468,7 @@ func TestUnReservePreBindPlugins(t *testing.T) {
t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1540,7 +1540,7 @@ func TestUnReserveBindPlugins(t *testing.T) {
t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -1688,7 +1688,7 @@ func TestBindPlugin(t *testing.T) {
if test.expectBoundByScheduler || test.expectBoundByPlugin { if test.expectBoundByScheduler || test.expectBoundByPlugin {
// bind plugins skipped to bind the pod // bind plugins skipped to bind the pod
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Fatalf("Expected the pod to be scheduled. error: %v", err) t.Fatalf("Expected the pod to be scheduled. error: %v", err)
} }
pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(testCtx.Ctx, pod.Name, metav1.GetOptions{}) pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(testCtx.Ctx, pod.Name, metav1.GetOptions{})
@ -1810,7 +1810,7 @@ func TestPostBindPlugin(t *testing.T) {
t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled) t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
select { select {
@ -1909,7 +1909,7 @@ func TestPermitPlugin(t *testing.T) {
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
} }
@ -1966,7 +1966,7 @@ func TestMultiplePermitPlugins(t *testing.T) {
} }
perPlugin2.allowAllPods() perPlugin2.allowAllPods()
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
@ -2083,10 +2083,10 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
permitPlugin.waitingPod, permitPlugin.rejectingPod) permitPlugin.waitingPod, permitPlugin.rejectingPod)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podA); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, podA); err != nil {
t.Errorf("Expected the first pod to be scheduled. error: %v", err) t.Errorf("Expected the first pod to be scheduled. error: %v", err)
} }
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podB); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, podB); err != nil {
t.Errorf("Expected the second pod to be scheduled. error: %v", err) t.Errorf("Expected the second pod to be scheduled. error: %v", err)
} }
if !((permitPlugin.waitingPod == podA.Name && permitPlugin.allowingPod == podB.Name) || if !((permitPlugin.waitingPod == podA.Name && permitPlugin.allowingPod == podB.Name) ||
@ -2150,7 +2150,7 @@ func TestFilterPlugin(t *testing.T) {
t.Errorf("Expected the filter plugin to be called at least 1 time, but got %v.", filterPlugin.numFilterCalled) t.Errorf("Expected the filter plugin to be called at least 1 time, but got %v.", filterPlugin.numFilterCalled)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
if filterPlugin.numFilterCalled != 1 { if filterPlugin.numFilterCalled != 1 {
@ -2204,7 +2204,7 @@ func TestPreScorePlugin(t *testing.T) {
t.Errorf("Expected a scheduling error, but got: %v", err) t.Errorf("Expected a scheduling error, but got: %v", err)
} }
} else { } else {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Expected the pod to be scheduled. error: %v", err) t.Errorf("Expected the pod to be scheduled. error: %v", err)
} }
} }
@ -2258,7 +2258,7 @@ func TestPreEnqueuePlugin(t *testing.T) {
} }
if tt.admitEnqueue { if tt.admitEnqueue {
if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod, 10*time.Second); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod, 10*time.Second); err != nil {
t.Errorf("Expected the pod to be schedulable, but got: %v", err) t.Errorf("Expected the pod to be schedulable, but got: %v", err)
} }
// Also verify enqueuePlugin is called. // Also verify enqueuePlugin is called.
@ -2396,7 +2396,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
t.Fatalf("Error while creating the running pod: %v", err) t.Fatalf("Error while creating the running pod: %v", err)
} }
// Wait until the pod to be scheduled. // Wait until the pod to be scheduled.
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, r); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, r); err != nil {
t.Fatalf("The running pod is expected to be scheduled: %v", err) t.Fatalf("The running pod is expected to be scheduled: %v", err)
} }
} }
@ -2425,7 +2425,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
t.Fatalf("Error while deleting the waiting pod: %v", err) t.Fatalf("Error while deleting the waiting pod: %v", err)
} }
} }
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, p); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, p); err != nil {
t.Fatalf("Expected the preemptor pod to be scheduled. error: %v", err) t.Fatalf("Expected the preemptor pod to be scheduled. error: %v", err)
} }
} }
@ -2592,7 +2592,7 @@ func TestActivatePods(t *testing.T) {
// Verify all pods to be scheduled. // Verify all pods to be scheduled.
for _, pod := range pods { for _, pod := range pods {
if err := testutils.WaitForPodToScheduleWithTimeout(cs, pod, wait.ForeverTestTimeout); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, pod, wait.ForeverTestTimeout); err != nil {
t.Fatalf("Failed to wait for Pod %v to be schedulable: %v", pod.Name, err) t.Fatalf("Failed to wait for Pod %v to be schedulable: %v", pod.Name, err)
} }
} }
@ -2768,7 +2768,7 @@ func TestPreEnqueuePluginEventsToRegister(t *testing.T) {
} }
// Wait for the pod schedulabled. // Wait for the pod schedulabled.
if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pausePod, 10*time.Second); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pausePod, 10*time.Second); err != nil {
t.Errorf("Expected the pod to be schedulable, but got: %v", err) t.Errorf("Expected the pod to be schedulable, but got: %v", err)
return return
} }
@ -2810,7 +2810,7 @@ func TestPreEnqueuePluginEventsToRegister(t *testing.T) {
} }
if expectedScheduled { if expectedScheduled {
if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, gatedPod, 10*time.Second); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, gatedPod, 10*time.Second); err != nil {
t.Errorf("Expected the pod to be schedulable, but got: %v", err) t.Errorf("Expected the pod to be schedulable, but got: %v", err)
} }
return return

View File

@ -85,8 +85,8 @@ const filterPluginName = "filter-plugin"
var lowPriority, mediumPriority, highPriority = int32(100), int32(200), int32(300) var lowPriority, mediumPriority, highPriority = int32(100), int32(200), int32(300)
func waitForNominatedNodeNameWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { func waitForNominatedNodeNameWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error {
if err := wait.PollUntilContextTimeout(context.TODO(), 100*time.Millisecond, timeout, false, func(ctx context.Context) (bool, error) { if err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, timeout, false, func(ctx context.Context) (bool, error) {
pod, err := cs.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{}) pod, err := cs.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
@ -101,8 +101,8 @@ func waitForNominatedNodeNameWithTimeout(cs clientset.Interface, pod *v1.Pod, ti
return nil return nil
} }
func waitForNominatedNodeName(cs clientset.Interface, pod *v1.Pod) error { func waitForNominatedNodeName(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error {
return waitForNominatedNodeNameWithTimeout(cs, pod, wait.ForeverTestTimeout) return waitForNominatedNodeNameWithTimeout(ctx, cs, pod, wait.ForeverTestTimeout)
} }
const tokenFilterName = "token-filter" const tokenFilterName = "token-filter"
@ -505,7 +505,7 @@ func TestPreemption(t *testing.T) {
} }
// Also check that the preemptor pod gets the NominatedNodeName field set. // Also check that the preemptor pod gets the NominatedNodeName field set.
if len(test.preemptedPodIndexes) > 0 { if len(test.preemptedPodIndexes) > 0 {
if err := waitForNominatedNodeName(cs, preemptor); err != nil { if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil {
t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err) t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err)
} }
} }
@ -1078,7 +1078,7 @@ func TestNonPreemption(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Error while creating victim: %v", err) t.Fatalf("Error while creating victim: %v", err)
} }
if err := waitForPodToScheduleWithTimeout(cs, victimPod, 5*time.Second); err != nil { if err := waitForPodToScheduleWithTimeout(testCtx.Ctx, cs, victimPod, 5*time.Second); err != nil {
t.Fatalf("victim %v should be become scheduled", victimPod.Name) t.Fatalf("victim %v should be become scheduled", victimPod.Name)
} }
@ -1087,7 +1087,7 @@ func TestNonPreemption(t *testing.T) {
t.Fatalf("Error while creating preemptor: %v", err) t.Fatalf("Error while creating preemptor: %v", err)
} }
err = waitForNominatedNodeNameWithTimeout(cs, preemptorPod, 5*time.Second) err = waitForNominatedNodeNameWithTimeout(testCtx.Ctx, cs, preemptorPod, 5*time.Second)
// test.PreemptionPolicy == nil means we expect the preemptor to be nominated. // test.PreemptionPolicy == nil means we expect the preemptor to be nominated.
expect := test.PreemptionPolicy == nil expect := test.PreemptionPolicy == nil
// err == nil indicates the preemptor is indeed nominated. // err == nil indicates the preemptor is indeed nominated.
@ -1169,7 +1169,7 @@ func TestDisablePreemption(t *testing.T) {
} }
// Ensure preemptor should not be nominated. // Ensure preemptor should not be nominated.
if err := waitForNominatedNodeNameWithTimeout(cs, preemptor, 5*time.Second); err == nil { if err := waitForNominatedNodeNameWithTimeout(testCtx.Ctx, cs, preemptor, 5*time.Second); err == nil {
t.Errorf("Preemptor %v should not be nominated", preemptor.Name) t.Errorf("Preemptor %v should not be nominated", preemptor.Name)
} }
@ -1358,7 +1358,7 @@ func TestPreemptionStarvation(t *testing.T) {
} }
// make sure that runningPods are all scheduled. // make sure that runningPods are all scheduled.
for _, p := range runningPods { for _, p := range runningPods {
if err := testutils.WaitForPodToSchedule(cs, p); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, p); err != nil {
t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err) t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err)
} }
} }
@ -1382,11 +1382,11 @@ func TestPreemptionStarvation(t *testing.T) {
t.Errorf("Error while creating the preempting pod: %v", err) t.Errorf("Error while creating the preempting pod: %v", err)
} }
// Check if .status.nominatedNodeName of the preemptor pod gets set. // Check if .status.nominatedNodeName of the preemptor pod gets set.
if err := waitForNominatedNodeName(cs, preemptor); err != nil { if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil {
t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err) t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err)
} }
// Make sure that preemptor is scheduled after preemptions. // Make sure that preemptor is scheduled after preemptions.
if err := testutils.WaitForPodToScheduleWithTimeout(cs, preemptor, 60*time.Second); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, preemptor, 60*time.Second); err != nil {
t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err) t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err)
} }
// Cleanup // Cleanup
@ -1463,7 +1463,7 @@ func TestPreemptionRaces(t *testing.T) {
} }
// make sure that initial Pods are all scheduled. // make sure that initial Pods are all scheduled.
for _, p := range initialPods { for _, p := range initialPods {
if err := testutils.WaitForPodToSchedule(cs, p); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, p); err != nil {
t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err) t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err)
} }
} }
@ -1482,11 +1482,11 @@ func TestPreemptionRaces(t *testing.T) {
} }
} }
// Check that the preemptor pod gets nominated node name. // Check that the preemptor pod gets nominated node name.
if err := waitForNominatedNodeName(cs, preemptor); err != nil { if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil {
t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err) t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err)
} }
// Make sure that preemptor is scheduled after preemptions. // Make sure that preemptor is scheduled after preemptions.
if err := testutils.WaitForPodToScheduleWithTimeout(cs, preemptor, 60*time.Second); err != nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, preemptor, 60*time.Second); err != nil {
t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err) t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err)
} }
@ -1549,7 +1549,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
// A slice of pods to be created in batch. // A slice of pods to be created in batch.
podsToCreate [][]*v1.Pod podsToCreate [][]*v1.Pod
// Each postCheck function is run after each batch of pods' creation. // Each postCheck function is run after each batch of pods' creation.
postChecks []func(cs clientset.Interface, pod *v1.Pod) error postChecks []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error
// Delete the fake node or not. Optional. // Delete the fake node or not. Optional.
deleteNode bool deleteNode bool
// Pods to be deleted. Optional. // Pods to be deleted. Optional.
@ -1576,7 +1576,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "3"}).Obj(), st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "3"}).Obj(),
}, },
}, },
postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{
testutils.WaitForPodToSchedule, testutils.WaitForPodToSchedule,
waitForNominatedNodeName, waitForNominatedNodeName,
waitForNominatedNodeName, waitForNominatedNodeName,
@ -1596,8 +1596,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(),
}, },
}, },
postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{
testutils.WaitForPodToSchedule,
waitForNominatedNodeName, waitForNominatedNodeName,
testutils.WaitForPodToSchedule, testutils.WaitForPodToSchedule,
}, },
@ -1614,7 +1613,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(),
}, },
}, },
postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{
testutils.WaitForPodToSchedule, testutils.WaitForPodToSchedule,
waitForNominatedNodeName, waitForNominatedNodeName,
}, },
@ -1633,7 +1632,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(),
}, },
}, },
postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{
testutils.WaitForPodToSchedule, testutils.WaitForPodToSchedule,
waitForNominatedNodeName, waitForNominatedNodeName,
}, },
@ -1683,7 +1682,7 @@ func TestNominatedNodeCleanUp(t *testing.T) {
// If necessary, run the post check function. // If necessary, run the post check function.
if len(tt.postChecks) > i && tt.postChecks[i] != nil { if len(tt.postChecks) > i && tt.postChecks[i] != nil {
for _, p := range pods { for _, p := range pods {
if err := tt.postChecks[i](cs, p); err != nil { if err := tt.postChecks[i](testCtx.Ctx, cs, p); err != nil {
t.Fatalf("Pod %v didn't pass the postChecks[%v]: %v", p.Name, i, err) t.Fatalf("Pod %v didn't pass the postChecks[%v]: %v", p.Name, i, err)
} }
} }
@ -1991,7 +1990,7 @@ func TestPDBInPreemption(t *testing.T) {
} }
// Also check if .status.nominatedNodeName of the preemptor pod gets set. // Also check if .status.nominatedNodeName of the preemptor pod gets set.
if len(test.preemptedPodIndexes) > 0 { if len(test.preemptedPodIndexes) > 0 {
if err := waitForNominatedNodeName(cs, preemptor); err != nil { if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil {
t.Errorf("Test [%v]: .status.nominatedNodeName was not set for pod %v/%v: %v", test.name, preemptor.Namespace, preemptor.Name, err) t.Errorf("Test [%v]: .status.nominatedNodeName was not set for pod %v/%v: %v", test.name, preemptor.Namespace, preemptor.Name, err)
} }
} }
@ -2484,7 +2483,7 @@ func TestReadWriteOncePodPreemption(t *testing.T) {
} }
// Also check that the preemptor pod gets the NominatedNodeName field set. // Also check that the preemptor pod gets the NominatedNodeName field set.
if len(test.preemptedPodIndexes) > 0 { if len(test.preemptedPodIndexes) > 0 {
if err := waitForNominatedNodeName(cs, preemptor); err != nil { if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil {
t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err) t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err)
} }
} }

View File

@ -235,7 +235,7 @@ func TestReScheduling(t *testing.T) {
} }
if test.wantScheduled { if test.wantScheduled {
if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil {
t.Errorf("Didn't expect the pod to be unschedulable. error: %v", err) t.Errorf("Didn't expect the pod to be unschedulable. error: %v", err)
} }
} else if test.wantError { } else if test.wantError {

View File

@ -141,7 +141,7 @@ func TestUnschedulableNodes(t *testing.T) {
} }
// There are no schedulable nodes - the pod shouldn't be scheduled. // There are no schedulable nodes - the pod shouldn't be scheduled.
err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, myPod, 2*time.Second) err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, myPod, 2*time.Second)
if err == nil { if err == nil {
t.Errorf("Test %d: Pod scheduled successfully on unschedulable nodes", i) t.Errorf("Test %d: Pod scheduled successfully on unschedulable nodes", i)
} }
@ -159,7 +159,7 @@ func TestUnschedulableNodes(t *testing.T) {
mod.makeSchedulable(t, schedNode, nodeLister, testCtx.ClientSet) mod.makeSchedulable(t, schedNode, nodeLister, testCtx.ClientSet)
// Wait until the pod is scheduled. // Wait until the pod is scheduled.
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, myPod); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, myPod); err != nil {
t.Errorf("Test %d: failed to schedule a pod: %v", i, err) t.Errorf("Test %d: failed to schedule a pod: %v", i, err)
} else { } else {
t.Logf("Test %d: Pod got scheduled on a schedulable node", i) t.Logf("Test %d: Pod got scheduled on a schedulable node", i)
@ -227,19 +227,19 @@ func TestMultipleSchedulers(t *testing.T) {
// - testPod, testPodFitsDefault should be scheduled // - testPod, testPodFitsDefault should be scheduled
// - testPodFitsFoo should NOT be scheduled // - testPodFitsFoo should NOT be scheduled
t.Logf("wait for pods scheduled") t.Logf("wait for pods scheduled")
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, testPod); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPod); err != nil {
t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPod.Name, err) t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPod.Name, err)
} else { } else {
t.Logf("Test MultiScheduler: %s Pod scheduled", testPod.Name) t.Logf("Test MultiScheduler: %s Pod scheduled", testPod.Name)
} }
if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, testPodFitsDefault); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPodFitsDefault); err != nil {
t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPodFitsDefault.Name, err) t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPodFitsDefault.Name, err)
} else { } else {
t.Logf("Test MultiScheduler: %s Pod scheduled", testPodFitsDefault.Name) t.Logf("Test MultiScheduler: %s Pod scheduled", testPodFitsDefault.Name)
} }
if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testPodFitsFoo, time.Second*5); err == nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testPodFitsFoo, time.Second*5); err == nil {
t.Errorf("Test MultiScheduler: %s Pod got scheduled, %v", testPodFitsFoo.Name, err) t.Errorf("Test MultiScheduler: %s Pod got scheduled, %v", testPodFitsFoo.Name, err)
} else { } else {
t.Logf("Test MultiScheduler: %s Pod not scheduled", testPodFitsFoo.Name) t.Logf("Test MultiScheduler: %s Pod not scheduled", testPodFitsFoo.Name)
@ -267,7 +267,7 @@ func TestMultipleSchedulers(t *testing.T) {
// 6. **check point-2**: // 6. **check point-2**:
// - testPodWithAnnotationFitsFoo should be scheduled // - testPodWithAnnotationFitsFoo should be scheduled
err = testutils.WaitForPodToSchedule(testCtx.ClientSet, testPodFitsFoo) err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPodFitsFoo)
if err != nil { if err != nil {
t.Errorf("Test MultiScheduler: %s Pod not scheduled, %v", testPodFitsFoo.Name, err) t.Errorf("Test MultiScheduler: %s Pod not scheduled, %v", testPodFitsFoo.Name, err)
} else { } else {
@ -371,7 +371,7 @@ func TestAllocatable(t *testing.T) {
} }
// 4. Test: this test pod should be scheduled since api-server will use Capacity as Allocatable // 4. Test: this test pod should be scheduled since api-server will use Capacity as Allocatable
err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testAllocPod, time.Second*5) err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testAllocPod, time.Second*5)
if err != nil { if err != nil {
t.Errorf("Test allocatable unawareness: %s Pod not scheduled: %v", testAllocPod.Name, err) t.Errorf("Test allocatable unawareness: %s Pod not scheduled: %v", testAllocPod.Name, err)
} else { } else {
@ -408,7 +408,7 @@ func TestAllocatable(t *testing.T) {
} }
// 7. Test: this test pod should not be scheduled since it request more than Allocatable // 7. Test: this test pod should not be scheduled since it request more than Allocatable
if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testAllocPod2, time.Second*5); err == nil { if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testAllocPod2, time.Second*5); err == nil {
t.Errorf("Test allocatable awareness: %s Pod got scheduled unexpectedly, %v", testAllocPod2.Name, err) t.Errorf("Test allocatable awareness: %s Pod got scheduled unexpectedly, %v", testAllocPod2.Name, err)
} else { } else {
t.Logf("Test allocatable awareness: %s Pod not scheduled as expected", testAllocPod2.Name) t.Logf("Test allocatable awareness: %s Pod not scheduled as expected", testAllocPod2.Name)
@ -575,7 +575,7 @@ func TestNodeEvents(t *testing.T) {
} }
// 1.3 verify pod1 is scheduled // 1.3 verify pod1 is scheduled
err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod1, time.Second*5) err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod1, time.Second*5)
if err != nil { if err != nil {
t.Errorf("Pod %s didn't schedule: %v", pod1.Name, err) t.Errorf("Pod %s didn't schedule: %v", pod1.Name, err)
} }
@ -615,7 +615,7 @@ func TestNodeEvents(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to create pod %v: %v", plugPod.Name, err) t.Fatalf("Failed to create pod %v: %v", plugPod.Name, err)
} }
err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, plugPod, time.Second*5) err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, plugPod, time.Second*5)
if err != nil { if err != nil {
t.Errorf("Pod %s didn't schedule: %v", plugPod.Name, err) t.Errorf("Pod %s didn't schedule: %v", plugPod.Name, err)
} }
@ -632,7 +632,7 @@ func TestNodeEvents(t *testing.T) {
t.Fatalf("Failed to update %s: %v", node2.Name, err) t.Fatalf("Failed to update %s: %v", node2.Name, err)
} }
err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod2, time.Second*5) err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod2, time.Second*5)
if err != nil { if err != nil {
t.Errorf("Pod %s didn't schedule: %v", pod2.Name, err) t.Errorf("Pod %s didn't schedule: %v", pod2.Name, err)
} }

View File

@ -545,7 +545,7 @@ func TestTaintNodeByCondition(t *testing.T) {
pods = append(pods, createdPod) pods = append(pods, createdPod)
if p.fits { if p.fits {
if err := testutils.WaitForPodToSchedule(cs, createdPod); err != nil { if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, createdPod); err != nil {
t.Errorf("Failed to schedule pod %s/%s on the node, err: %v", t.Errorf("Failed to schedule pod %s/%s on the node, err: %v",
pod.Namespace, pod.Name, err) pod.Namespace, pod.Name, err)
} }

View File

@ -631,14 +631,14 @@ func InitTestSchedulerWithOptions(
// WaitForPodToScheduleWithTimeout waits for a pod to get scheduled and returns // WaitForPodToScheduleWithTimeout waits for a pod to get scheduled and returns
// an error if it does not scheduled within the given timeout. // an error if it does not scheduled within the given timeout.
func WaitForPodToScheduleWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { func WaitForPodToScheduleWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error {
return wait.PollUntilContextTimeout(context.TODO(), 100*time.Millisecond, timeout, false, PodScheduled(cs, pod.Namespace, pod.Name)) return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, timeout, false, PodScheduled(cs, pod.Namespace, pod.Name))
} }
// WaitForPodToSchedule waits for a pod to get scheduled and returns an error if // WaitForPodToSchedule waits for a pod to get scheduled and returns an error if
// it does not get scheduled within the timeout duration (30 seconds). // it does not get scheduled within the timeout duration (30 seconds).
func WaitForPodToSchedule(cs clientset.Interface, pod *v1.Pod) error { func WaitForPodToSchedule(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error {
return WaitForPodToScheduleWithTimeout(cs, pod, 30*time.Second) return WaitForPodToScheduleWithTimeout(ctx, cs, pod, 30*time.Second)
} }
// PodScheduled checks if the pod has been scheduled // PodScheduled checks if the pod has been scheduled
@ -904,7 +904,7 @@ func RunPausePod(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create pause pod: %v", err) return nil, fmt.Errorf("failed to create pause pod: %v", err)
} }
if err = WaitForPodToSchedule(cs, pod); err != nil { if err = WaitForPodToSchedule(context.TODO(), cs, pod); err != nil {
return pod, fmt.Errorf("Pod %v/%v didn't schedule successfully. Error: %v", pod.Namespace, pod.Name, err) return pod, fmt.Errorf("Pod %v/%v didn't schedule successfully. Error: %v", pod.Namespace, pod.Name, err)
} }
if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil { if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil {
@ -941,7 +941,7 @@ func RunPodWithContainers(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create pod-with-containers: %v", err) return nil, fmt.Errorf("failed to create pod-with-containers: %v", err)
} }
if err = WaitForPodToSchedule(cs, pod); err != nil { if err = WaitForPodToSchedule(context.TODO(), cs, pod); err != nil {
return pod, fmt.Errorf("Pod %v didn't schedule successfully. Error: %v", pod.Name, err) return pod, fmt.Errorf("Pod %v didn't schedule successfully. Error: %v", pod.Name, err)
} }
if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil { if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil {