From 1ed3e8e55322d8058550f1734dfc00d4cb48950d Mon Sep 17 00:00:00 2001 From: Yuki Iwai Date: Mon, 17 Jul 2023 23:05:25 +0900 Subject: [PATCH] Remove duplicated test case for unsuspending PyTorchJobs Signed-off-by: Yuki Iwai --- .../pytorch/pytorchjob_controller_test.go | 93 +++++-------------- 1 file changed, 25 insertions(+), 68 deletions(-) diff --git a/pkg/controller.v1/pytorch/pytorchjob_controller_test.go b/pkg/controller.v1/pytorch/pytorchjob_controller_test.go index 8ea82cd891..07c147c4eb 100644 --- a/pkg/controller.v1/pytorch/pytorchjob_controller_test.go +++ b/pkg/controller.v1/pytorch/pytorchjob_controller_test.go @@ -196,7 +196,7 @@ var _ = Describe("PyTorchJob controller", func() { Expect(cond.Status).To(Equal(corev1.ConditionTrue)) }) - It("Shouldn't create resources if PyTorchJob is suspended; Should create resources once PyTorchJob is unsuspended", func() { + It("Shouldn't create resources if PyTorchJob is suspended", func() { By("By creating a new PyTorchJob with suspend=true") job.Spec.RunPolicy.Suspend = pointer.Bool(true) job.Spec.PyTorchReplicaSpecs[kubeflowv1.PyTorchJobReplicaTypeWorker].Replicas = pointer.Int32(1) @@ -247,68 +247,6 @@ var _ = Describe("PyTorchJob controller", func() { Message: fmt.Sprintf("PyTorchJob %s is suspended.", name), }, }, testutil.IgnoreJobConditionsTimes)) - - By("Unsuspending the PyTorchJob") - Eventually(func() error { - Expect(testK8sClient.Get(ctx, jobKey, created)).Should(Succeed()) - created.Spec.RunPolicy.Suspend = pointer.Bool(false) - return testK8sClient.Update(ctx, created) - }, testutil.Timeout, testutil.Interval).Should(Succeed()) - Eventually(func() *metav1.Time { - Expect(testK8sClient.Get(ctx, jobKey, created)).Should(Succeed()) - return created.Status.StartTime - }, testutil.Timeout, testutil.Interval).ShouldNot(BeNil()) - - By("Check if the pods and services are created") - Eventually(func() error { - return testK8sClient.Get(ctx, masterKey, masterPod) - }, testutil.Timeout, testutil.Interval).Should(BeNil()) - Eventually(func() error { - return testK8sClient.Get(ctx, worker0Key, workerPod) - }, testutil.Timeout, testutil.Interval).Should(BeNil()) - Eventually(func() error { - return testK8sClient.Get(ctx, masterKey, masterSvc) - }, testutil.Timeout, testutil.Interval).Should(BeNil()) - Eventually(func() error { - return testK8sClient.Get(ctx, worker0Key, workerSvc) - }, testutil.Timeout, testutil.Interval).Should(BeNil()) - - By("Updating Pod's condition with running") - Eventually(func() error { - Expect(testK8sClient.Get(ctx, masterKey, masterPod)).Should(Succeed()) - masterPod.Status.Phase = corev1.PodRunning - return testK8sClient.Status().Update(ctx, masterPod) - }, testutil.Timeout, testutil.Interval).Should(Succeed()) - Eventually(func() error { - Expect(testK8sClient.Get(ctx, worker0Key, workerPod)).Should(Succeed()) - workerPod.Status.Phase = corev1.PodRunning - return testK8sClient.Status().Update(ctx, workerPod) - }, testutil.Timeout, testutil.Interval).Should(Succeed()) - - By("Checking the PyTorchJob has resumed conditions") - Eventually(func() []kubeflowv1.JobCondition { - Expect(testK8sClient.Get(ctx, jobKey, created)).Should(Succeed()) - return created.Status.Conditions - }, testutil.Timeout, testutil.Interval).Should(BeComparableTo([]kubeflowv1.JobCondition{ - { - Type: kubeflowv1.JobCreated, - Status: corev1.ConditionTrue, - Reason: commonutil.NewReason(kubeflowv1.PytorchJobKind, commonutil.JobCreatedReason), - Message: fmt.Sprintf("PyTorchJob %s is created.", name), - }, - { - Type: kubeflowv1.JobSuspended, - Status: corev1.ConditionFalse, - Reason: commonutil.NewReason(kubeflowv1.PytorchJobKind, commonutil.JobResumedReason), - Message: fmt.Sprintf("PyTorchJob %s is resumed.", name), - }, - { - Type: kubeflowv1.JobRunning, - Status: corev1.ConditionTrue, - Reason: commonutil.NewReason(kubeflowv1.PytorchJobKind, commonutil.JobRunningReason), - Message: fmt.Sprintf("PyTorchJob %s is running.", name), - }, - }, testutil.IgnoreJobConditionsTimes)) }) It("Should delete resources after PyTorchJob is suspended; Should resume PyTorchJob after PyTorchJob is unsuspended", func() { @@ -440,23 +378,42 @@ var _ = Describe("PyTorchJob controller", func() { }, }, testutil.IgnoreJobConditionsTimes)) - By("Updating the PytorchJob with suspend=false") + By("Unsuspending the PyTorchJob") Eventually(func() error { Expect(testK8sClient.Get(ctx, jobKey, created)).Should(Succeed()) created.Spec.RunPolicy.Suspend = pointer.Bool(false) return testK8sClient.Update(ctx, created) }, testutil.Timeout, testutil.Interval).Should(Succeed()) + Eventually(func() *metav1.Time { + Expect(testK8sClient.Get(ctx, jobKey, created)).Should(Succeed()) + return created.Status.StartTime + }, testutil.Timeout, testutil.Interval).ShouldNot(BeNil()) - By("Updating the pod's phase with Running") + By("Check if the pods and services are created") Eventually(func() error { - errMaster := testK8sClient.Get(ctx, masterKey, masterPod) - return errMaster - }, testutil.Timeout, testutil.Interval).Should(Succeed()) + return testK8sClient.Get(ctx, masterKey, masterPod) + }, testutil.Timeout, testutil.Interval).Should(BeNil()) + Eventually(func() error { + return testK8sClient.Get(ctx, worker0Key, workerPod) + }, testutil.Timeout, testutil.Interval).Should(BeNil()) + Eventually(func() error { + return testK8sClient.Get(ctx, masterKey, masterSvc) + }, testutil.Timeout, testutil.Interval).Should(BeNil()) + Eventually(func() error { + return testK8sClient.Get(ctx, worker0Key, workerSvc) + }, testutil.Timeout, testutil.Interval).Should(BeNil()) + + By("Updating Pod's condition with running") Eventually(func() error { Expect(testK8sClient.Get(ctx, masterKey, masterPod)).Should(Succeed()) masterPod.Status.Phase = corev1.PodRunning return testK8sClient.Status().Update(ctx, masterPod) }, testutil.Timeout, testutil.Interval).Should(Succeed()) + Eventually(func() error { + Expect(testK8sClient.Get(ctx, worker0Key, workerPod)).Should(Succeed()) + workerPod.Status.Phase = corev1.PodRunning + return testK8sClient.Status().Update(ctx, workerPod) + }, testutil.Timeout, testutil.Interval).Should(Succeed()) By("Checking if the PyTorchJob has resumed conditions") Eventually(func() []kubeflowv1.JobCondition {