Skip to content

Commit 8c1831a

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
test: Write logs also for jobs that have timed out
1 parent 4048a26 commit 8c1831a

4 files changed

+14
-9
lines changed

test/e2e/mnist_pytorch_mcad_job_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ func TestMNISTPyTorchMCAD(t *testing.T) {
145145
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutMedium).
146146
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
147147

148+
// Retrieving the job logs once it has completed or timed out
149+
defer WriteJobLogs(test, job.Namespace, job.Name)
150+
148151
test.T().Logf("Waiting for Job %s/%s to complete", job.Namespace, job.Name)
149152
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutLong).Should(
150153
Or(
151154
WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)),
152155
WithTransform(ConditionStatus(batchv1.JobFailed), Equal(corev1.ConditionTrue)),
153156
))
154157

155-
// Retrieve the job logs
156-
WriteJobLogs(test, job.Namespace, job.Name)
157-
158158
// Assert the job has completed successfully
159159
test.Expect(GetJob(test, job.Namespace, job.Name)).
160160
To(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)))

test/e2e/mnist_raycluster_sdk_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ func TestMNISTRayClusterSDK(t *testing.T) {
194194
test.Expect(err).NotTo(HaveOccurred())
195195
test.T().Logf("Created Job %s/%s successfully", job.Namespace, job.Name)
196196

197+
// Retrieving the job logs once it has completed or timed out
198+
defer WriteJobLogs(test, job.Namespace, job.Name)
199+
197200
test.T().Logf("Waiting for Job %s/%s to complete", job.Namespace, job.Name)
198201
test.Eventually(Job(test, job.Namespace, job.Name), TestTimeoutLong).Should(
199202
Or(
200203
WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)),
201204
WithTransform(ConditionStatus(batchv1.JobFailed), Equal(corev1.ConditionTrue)),
202205
))
203206

204-
// Retrieve the job logs
205-
WriteJobLogs(test, job.Namespace, job.Name)
206-
207207
// Assert the job has completed successfully
208208
test.Expect(GetJob(test, job.Namespace, job.Name)).
209209
To(WithTransform(ConditionStatus(batchv1.JobComplete), Equal(corev1.ConditionTrue)))

test/e2e/mnist_rayjob_mcad_raycluster_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ func TestMNISTRayJobMCADRayCluster(t *testing.T) {
252252
test.Expect(err).NotTo(HaveOccurred())
253253
test.T().Logf("Created RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name)
254254

255+
// Retrieving the job logs once it has completed or timed out
256+
defer WriteRayJobLogs(test, rayJob.Namespace, rayJob.Name)
257+
255258
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
256259
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
257260
Should(WithTransform(RayJobStatus, Satisfy(rayv1alpha1.IsJobTerminal)))
258261

259-
test.T().Logf("Retrieving RayJob %s/%s logs", rayJob.Namespace, rayJob.Name)
260-
WriteToOutputDir(test, rayJob.Name, Log, GetRayJobLogs(test, rayJob.Namespace, rayJob.Name))
261-
262262
// Assert the Ray job has completed successfully
263263
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
264264
To(WithTransform(RayJobStatus, Equal(rayv1alpha1.JobStatusSucceeded)))

test/support/ray.go

+5
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ func GetRayJobLogs(t Test, namespace, name string) []byte {
6363

6464
return []byte(body["logs"])
6565
}
66+
67+
func WriteRayJobLogs(t Test, namespace, name string) {
68+
t.T().Logf("Retrieving RayJob %s/%s logs", namespace, name)
69+
WriteToOutputDir(t, name, Log, GetRayJobLogs(t, namespace, name))
70+
}

0 commit comments

Comments
 (0)