Skip to content

Commit f7b7a3a

Browse files
astefanuttiopenshift-merge-robot
authored andcommitted
test: Print Ray job logs after successful or failed completion
1 parent 9c79ab0 commit f7b7a3a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

test/e2e/mnist_rayjob_mcad_raycluster_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ func TestMNISTRayJobMCADRayCluster(t *testing.T) {
250250
test.Expect(err).NotTo(HaveOccurred())
251251
test.T().Logf("Created RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name)
252252

253-
test.T().Logf("Waiting for RayJob %s/%s to complete successfully", rayJob.Namespace, rayJob.Name)
254-
test.Eventually(RayJob(test, namespace, rayJob.Name), TestTimeoutLong).
255-
Should(WithTransform(RayJobStatus, Equal(rayv1alpha1.JobStatusSucceeded)))
256-
257-
rayJob, err = test.Client().Ray().RayV1alpha1().RayJobs(namespace.Name).Get(test.Ctx(), rayJob.Name, metav1.GetOptions{})
258-
test.Expect(err).NotTo(HaveOccurred())
253+
test.T().Logf("Waiting for RayJob %s/%s to complete", rayJob.Namespace, rayJob.Name)
254+
test.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutLong).
255+
Should(WithTransform(RayJobStatus, Satisfy(rayv1alpha1.IsJobTerminal)))
259256

260257
test.T().Logf("Printing RayJob %s/%s logs", rayJob.Namespace, rayJob.Name)
261-
test.T().Log(GetRayJobLogs(test, rayJob))
258+
test.T().Log(GetRayJobLogs(test, rayJob.Namespace, rayJob.Name))
259+
260+
// Assert the Ray job has completed successfully
261+
test.Expect(GetRayJob(test, rayJob.Namespace, rayJob.Name)).
262+
To(WithTransform(RayJobStatus, Equal(rayv1alpha1.JobStatusSucceeded)))
262263
}

test/support/ray.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,35 @@ import (
2121

2222
"github.com/onsi/gomega"
2323

24-
corev1 "k8s.io/api/core/v1"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2625

2726
rayv1alpha1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1alpha1"
2827
)
2928

3029
const RayJobDefaultClusterSelectorKey = "ray.io/cluster"
3130

32-
func RayJob(t Test, namespace *corev1.Namespace, name string) func(g gomega.Gomega) *rayv1alpha1.RayJob {
31+
func RayJob(t Test, namespace, name string) func(g gomega.Gomega) *rayv1alpha1.RayJob {
3332
return func(g gomega.Gomega) *rayv1alpha1.RayJob {
34-
job, err := t.Client().Ray().RayV1alpha1().RayJobs(namespace.Name).Get(t.Ctx(), name, metav1.GetOptions{})
33+
job, err := t.Client().Ray().RayV1alpha1().RayJobs(namespace).Get(t.Ctx(), name, metav1.GetOptions{})
3534
g.Expect(err).NotTo(gomega.HaveOccurred())
3635
return job
3736
}
3837
}
3938

39+
func GetRayJob(t Test, namespace, name string) *rayv1alpha1.RayJob {
40+
t.T().Helper()
41+
return RayJob(t, namespace, name)(t)
42+
}
43+
4044
func RayJobStatus(job *rayv1alpha1.RayJob) rayv1alpha1.JobStatus {
4145
return job.Status.JobStatus
4246
}
4347

44-
func GetRayJobLogs(t Test, job *rayv1alpha1.RayJob) string {
48+
func GetRayJobLogs(t Test, namespace, name string) string {
4549
t.T().Helper()
50+
51+
job := GetRayJob(t, namespace, name)
52+
4653
response := t.Client().Core().CoreV1().RESTClient().
4754
Get().
4855
AbsPath("/api/v1/namespaces", job.Namespace, "services", "http:"+job.Status.RayClusterName+"-head-svc:dashboard", "proxy", "api", "jobs", job.Status.JobId, "logs").

0 commit comments

Comments
 (0)