Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust e2e tests to verify deletion of resources #592

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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), TestTimeoutShort).Should(BeEmpty())
}
40 changes: 23 additions & 17 deletions test/e2e/mnist_rayjob_raycluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,22 @@ func runMnistRayJobRayCluster(t *testing.T, accelerator string, numberOfGpus int
test.T().Logf("Connecting to Ray cluster at: %s", rayDashboardURL.String())
rayClient := NewRayClusterClient(rayDashboardURL)

// Wait for Ray job id to be available, this value is needed for writing logs in defer
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
Should(WithTransform(RayJobId, Not(BeEmpty())))

// Retrieving the job logs once it has completed or timed out
defer WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))

test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal)))

// Assert the Ray job has completed successfully
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))

WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))

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), TestTimeoutShort).Should(BeEmpty())
}

func TestMnistRayJobRayClusterAppWrapperCpu(t *testing.T) {
Expand Down Expand Up @@ -143,11 +145,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 All @@ -166,20 +170,22 @@ func runMnistRayJobRayClusterAppWrapper(t *testing.T, accelerator string, number
test.T().Logf("Connecting to Ray cluster at: %s", rayDashboardURL.String())
rayClient := NewRayClusterClient(rayDashboardURL)

// Wait for Ray job id to be available, this value is needed for writing logs in defer
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
Should(WithTransform(RayJobId, Not(BeEmpty())))

// Retrieving the job logs once it has completed or timed out
defer WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))

test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal)))

// Assert the Ray job has completed successfully
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))

WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))

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), TestTimeoutShort).Should(BeEmpty())
}

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