Skip to content

Commit

Permalink
Adjust e2e tests to verify deletion of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sutaakar committed Jul 18, 2024
1 parent 26a1276 commit 4b0d6af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 18 additions & 5 deletions test/e2e/mnist_pytorch_appwrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func runMnistPyTorchAppWrapper(t *testing.T, accelerator string) {
Kind: "AppWrapper",
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: "mnist",
GenerateName: "mnist-",
Namespace: namespace.Name,
Labels: map[string]string{"kueue.x-k8s.io/queue-name": localQueue.Name},
},
Expand All @@ -162,20 +162,33 @@ func runMnistPyTorchAppWrapper(t *testing.T, accelerator string) {
awMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(aw)
test.Expect(err).NotTo(HaveOccurred())
unstruct := unstructured.Unstructured{Object: awMap}
_, err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
unstructp, err := test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
test.Expect(err).NotTo(HaveOccurred())
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructp.Object, aw)
test.Expect(err).NotTo(HaveOccurred())
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.GenerateName)
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.Name)

test.T().Logf("Waiting for AppWrapper %s/%s to be running", aw.Namespace, aw.GenerateName)
test.T().Logf("Waiting for AppWrapper %s/%s to be running", aw.Namespace, aw.Name)
test.Eventually(AppWrappers(test, namespace), TestTimeoutMedium).
Should(ContainElement(WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperRunning))))

test.T().Logf("Waiting for AppWrapper %s/%s to complete", job.Namespace, job.Name)
test.T().Logf("Waiting for AppWrapper %s/%s to complete", aw.Namespace, aw.Name)
test.Eventually(AppWrappers(test, namespace), TestTimeoutLong).Should(
ContainElement(
Or(
WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperSucceeded)),
WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperFailed)),
),
))

// Assert the AppWrapper has completed successfully
test.Expect(AppWrappers(test, namespace)(test)).
To(ContainElement(WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperSucceeded))))

test.T().Logf("Deleting AppWrapper %s/%s", aw.Namespace, aw.Name)
err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Delete(test.Ctx(), aw.Name, metav1.DeleteOptions{})
test.Expect(err).NotTo(HaveOccurred())

test.T().Logf("Waiting for AppWrapper %s/%s to be deleted", aw.Namespace, aw.Name)
test.Eventually(AppWrappers(test, namespace), TestTimeoutLong).Should(BeEmpty())
}
26 changes: 23 additions & 3 deletions test/e2e/mnist_rayjob_raycluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func runMnistRayJobRayCluster(t *testing.T, accelerator string, numberOfGpus int
// Assert the Ray job has completed successfully
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))

test.T().Logf("Deleting RayCluster %s/%s", rayCluster.Namespace, rayCluster.Name)
err = test.Client().Ray().RayV1().RayClusters(namespace.Name).Delete(test.Ctx(), rayCluster.Name, metav1.DeleteOptions{})
test.Expect(err).NotTo(HaveOccurred())

test.T().Logf("Waiting for RayCluster %s/%s to be deleted", rayCluster.Namespace, rayCluster.Name)
test.Eventually(RayClusters(test, namespace.Name), TestTimeoutLong).Should(BeEmpty())
}

func TestMnistRayJobRayClusterAppWrapperCpu(t *testing.T) {
Expand Down Expand Up @@ -143,11 +150,13 @@ func runMnistRayJobRayClusterAppWrapper(t *testing.T, accelerator string, number
awMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(aw)
test.Expect(err).NotTo(HaveOccurred())
unstruct := unstructured.Unstructured{Object: awMap}
_, err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
unstructp, err := test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
test.Expect(err).NotTo(HaveOccurred())
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructp.Object, aw)
test.Expect(err).NotTo(HaveOccurred())
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.GenerateName)
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.Name)

test.T().Logf("Waiting for AppWrapper %s/%s to be running", aw.Namespace, aw.GenerateName)
test.T().Logf("Waiting for AppWrapper %s/%s to be running", aw.Namespace, aw.Name)
test.Eventually(AppWrappers(test, namespace), TestTimeoutMedium).
Should(ContainElement(WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperRunning))))

Expand Down Expand Up @@ -180,6 +189,17 @@ func runMnistRayJobRayClusterAppWrapper(t *testing.T, accelerator string, number
// Assert the Ray job has completed successfully
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))

// Assert the AppWrapper has completed successfully
test.Expect(AppWrappers(test, namespace)(test)).
To(ContainElement(WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperSucceeded))))

test.T().Logf("Deleting AppWrapper %s/%s", aw.Namespace, aw.Name)
err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Delete(test.Ctx(), aw.Name, metav1.DeleteOptions{})
test.Expect(err).NotTo(HaveOccurred())

test.T().Logf("Waiting for AppWrapper %s/%s to be deleted", aw.Namespace, aw.Name)
test.Eventually(AppWrappers(test, namespace), TestTimeoutLong).Should(BeEmpty())
}

func constructMNISTConfigMap(test Test, namespace *corev1.Namespace) *corev1.ConfigMap {
Expand Down

0 comments on commit 4b0d6af

Please sign in to comment.