Skip to content

Commit 89d6a81

Browse files
committed
Adjust e2e tests to verify deletion of resources
1 parent 26a1276 commit 89d6a81

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

Diff for: test/e2e/mnist_pytorch_appwrapper_test.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func runMnistPyTorchAppWrapper(t *testing.T, accelerator string) {
145145
Kind: "AppWrapper",
146146
},
147147
ObjectMeta: metav1.ObjectMeta{
148-
GenerateName: "mnist",
148+
GenerateName: "mnist-",
149149
Namespace: namespace.Name,
150150
Labels: map[string]string{"kueue.x-k8s.io/queue-name": localQueue.Name},
151151
},
@@ -162,20 +162,33 @@ func runMnistPyTorchAppWrapper(t *testing.T, accelerator string) {
162162
awMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(aw)
163163
test.Expect(err).NotTo(HaveOccurred())
164164
unstruct := unstructured.Unstructured{Object: awMap}
165-
_, err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
165+
unstructp, err := test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Create(test.Ctx(), &unstruct, metav1.CreateOptions{})
166+
test.Expect(err).NotTo(HaveOccurred())
167+
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructp.Object, aw)
166168
test.Expect(err).NotTo(HaveOccurred())
167-
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.GenerateName)
169+
test.T().Logf("Created AppWrapper %s/%s successfully", aw.Namespace, aw.Name)
168170

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

173-
test.T().Logf("Waiting for AppWrapper %s/%s to complete", job.Namespace, job.Name)
175+
test.T().Logf("Waiting for AppWrapper %s/%s to complete", aw.Namespace, aw.Name)
174176
test.Eventually(AppWrappers(test, namespace), TestTimeoutLong).Should(
175177
ContainElement(
176178
Or(
177179
WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperSucceeded)),
178180
WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperFailed)),
179181
),
180182
))
183+
184+
// Assert the AppWrapper has completed successfully
185+
test.Expect(AppWrappers(test, namespace)(test)).
186+
To(ContainElement(WithTransform(AppWrapperPhase, Equal(mcadv1beta2.AppWrapperSucceeded))))
187+
188+
test.T().Logf("Deleting AppWrapper %s/%s", aw.Namespace, aw.Name)
189+
err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Delete(test.Ctx(), aw.Name, metav1.DeleteOptions{})
190+
test.Expect(err).NotTo(HaveOccurred())
191+
192+
test.T().Logf("Waiting for AppWrapper %s/%s to be deleted", aw.Namespace, aw.Name)
193+
test.Eventually(AppWrappers(test, namespace), TestTimeoutShort).Should(BeEmpty())
181194
}

Diff for: test/e2e/mnist_rayjob_raycluster_test.go

+23-17
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,22 @@ func runMnistRayJobRayCluster(t *testing.T, accelerator string, numberOfGpus int
8181
test.T().Logf("Connecting to Ray cluster at: %s", rayDashboardURL.String())
8282
rayClient := NewRayClusterClient(rayDashboardURL)
8383

84-
// Wait for Ray job id to be available, this value is needed for writing logs in defer
85-
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
86-
Should(WithTransform(RayJobId, Not(BeEmpty())))
87-
88-
// Retrieving the job logs once it has completed or timed out
89-
defer WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))
90-
9184
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
9285
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
9386
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal)))
9487

9588
// Assert the Ray job has completed successfully
9689
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
9790
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))
91+
92+
WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))
93+
94+
test.T().Logf("Deleting RayCluster %s/%s", rayCluster.Namespace, rayCluster.Name)
95+
err = test.Client().Ray().RayV1().RayClusters(namespace.Name).Delete(test.Ctx(), rayCluster.Name, metav1.DeleteOptions{})
96+
test.Expect(err).NotTo(HaveOccurred())
97+
98+
test.T().Logf("Waiting for RayCluster %s/%s to be deleted", rayCluster.Namespace, rayCluster.Name)
99+
test.Eventually(RayClusters(test, namespace.Name), TestTimeoutShort).Should(BeEmpty())
98100
}
99101

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

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

@@ -166,20 +170,22 @@ func runMnistRayJobRayClusterAppWrapper(t *testing.T, accelerator string, number
166170
test.T().Logf("Connecting to Ray cluster at: %s", rayDashboardURL.String())
167171
rayClient := NewRayClusterClient(rayDashboardURL)
168172

169-
// Wait for Ray job id to be available, this value is needed for writing logs in defer
170-
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
171-
Should(WithTransform(RayJobId, Not(BeEmpty())))
172-
173-
// Retrieving the job logs once it has completed or timed out
174-
defer WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))
175-
176173
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
177174
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
178175
Should(WithTransform(RayJobStatus, Satisfy(rayv1.IsJobTerminal)))
179176

180177
// Assert the Ray job has completed successfully
181178
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
182179
To(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))
180+
181+
WriteRayJobAPILogs(test, rayClient, GetRayJobId(test, rayJob.Namespace, rayJob.Name))
182+
183+
test.T().Logf("Deleting AppWrapper %s/%s", aw.Namespace, aw.Name)
184+
err = test.Client().Dynamic().Resource(appWrapperResource).Namespace(namespace.Name).Delete(test.Ctx(), aw.Name, metav1.DeleteOptions{})
185+
test.Expect(err).NotTo(HaveOccurred())
186+
187+
test.T().Logf("Waiting for AppWrapper %s/%s to be deleted", aw.Namespace, aw.Name)
188+
test.Eventually(AppWrappers(test, namespace), TestTimeoutShort).Should(BeEmpty())
183189
}
184190

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

0 commit comments

Comments
 (0)