Skip to content

Commit cfd0bfa

Browse files
[Feat] Add e2e test for applying ray-job.interactive-mode.yaml (#3779) (#3787)
Co-authored-by: Cheyu Wu <[email protected]>
1 parent 08f304f commit cfd0bfa

File tree

2 files changed

+57
-32
lines changed

2 files changed

+57
-32
lines changed

ray-operator/config/samples/ray-job.interactive-mode.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ apiVersion: ray.io/v1
22
kind: RayJob
33
metadata:
44
name: rayjob-interactive-mode
5-
namespace: default
65
spec:
76
# InteractiveMode means KubeRay doesn't submit the job for you.
87
# KubeRay will create the RayJob and transition it to the Waiting state.

ray-operator/test/sampleyaml/rayjob_test.go

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
. "github.com/onsi/gomega"
8+
corev1 "k8s.io/api/core/v1"
89

910
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1011
. "github.com/ray-project/kuberay/ray-operator/test/support"
@@ -33,49 +34,74 @@ func TestRayJob(t *testing.T) {
3334
test := With(t)
3435
g := NewWithT(t)
3536
g.ConfigureWithT(WithRayJobResourceLogger(test))
36-
3737
yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name)
3838
namespace := test.NewTestNamespace()
3939
rayJobFromYaml := DeserializeRayJobYAML(test, yamlFilePath)
4040
KubectlApplyYAML(test, yamlFilePath, namespace.Name)
4141

42-
rayJob, err := GetRayJob(test, namespace.Name, rayJobFromYaml.Name)
43-
g.Expect(err).NotTo(HaveOccurred())
44-
g.Expect(rayJob).NotTo(BeNil())
42+
checkRayJobCluster(test, g, rayJobFromYaml, namespace)
4543

46-
// Wait for RayCluster name to be populated
47-
g.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
48-
Should(WithTransform(RayJobClusterName, Not(BeEmpty())))
44+
g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobDeploymentStatus, Equal(rayv1.JobDeploymentStatusComplete)))
45+
g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))
46+
})
47+
}
48+
}
4949

50-
rayJob, err = GetRayJob(test, rayJob.Namespace, rayJob.Name)
51-
g.Expect(err).NotTo(HaveOccurred())
52-
g.Expect(rayJob).NotTo(BeNil())
50+
func TestRayJobInteractiveMode(t *testing.T) {
51+
tests := []struct {
52+
name string
53+
}{
54+
{
55+
name: "ray-job.interactive-mode.yaml",
56+
},
57+
}
5358

54-
LogWithTimestamp(test.T(), "Waiting for RayCluster %s/%s to be ready", namespace.Name, rayJob.Status.RayClusterName)
55-
g.Eventually(RayCluster(test, namespace.Name, rayJob.Status.RayClusterName), TestTimeoutMedium).
56-
Should(WithTransform(RayClusterState, Equal(rayv1.Ready)))
57-
rayCluster, err := GetRayCluster(test, namespace.Name, rayJob.Status.RayClusterName)
58-
g.Expect(err).NotTo(HaveOccurred())
59+
for _, tt := range tests {
60+
t.Run(tt.name, func(t *testing.T) {
61+
test := With(t)
62+
g := NewWithT(t)
63+
g.ConfigureWithT(WithRayJobResourceLogger(test))
64+
yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name)
65+
namespace := test.NewTestNamespace()
66+
rayJobFromYaml := DeserializeRayJobYAML(test, yamlFilePath)
67+
KubectlApplyYAML(test, yamlFilePath, namespace.Name)
68+
checkRayJobCluster(test, g, rayJobFromYaml, namespace)
69+
})
70+
}
71+
}
5972

60-
// Check if the RayCluster created correct number of pods
61-
var desiredWorkerPods int32
62-
if rayCluster.Spec.WorkerGroupSpecs != nil {
63-
for _, workerGroupSpec := range rayCluster.Spec.WorkerGroupSpecs {
64-
desiredWorkerPods += (*workerGroupSpec.Replicas * workerGroupSpec.NumOfHosts)
65-
}
66-
}
67-
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(HaveLen(int(desiredWorkerPods)))
68-
g.Expect(GetRayCluster(test, namespace.Name, rayCluster.Name)).To(WithTransform(RayClusterDesiredWorkerReplicas, Equal(desiredWorkerPods)))
73+
func checkRayJobCluster(test Test, g *WithT, rayJobFromYaml *rayv1.RayJob, namespace *corev1.Namespace) {
74+
rayJob, err := GetRayJob(test, namespace.Name, rayJobFromYaml.Name)
75+
g.Expect(err).NotTo(HaveOccurred())
76+
g.Expect(rayJob).NotTo(BeNil())
6977

70-
// Check if the head pod is ready
71-
g.Eventually(HeadPod(test, rayCluster), TestTimeoutShort).Should(WithTransform(IsPodRunningAndReady, BeTrue()))
78+
// Wait for RayCluster name to be populated
79+
g.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
80+
Should(WithTransform(RayJobClusterName, Not(BeEmpty())))
7281

73-
// Check if all worker pods are ready
74-
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(WithTransform(AllPodsRunningAndReady, BeTrue()))
82+
rayJob, err = GetRayJob(test, rayJob.Namespace, rayJob.Name)
83+
g.Expect(err).NotTo(HaveOccurred())
84+
g.Expect(rayJob).NotTo(BeNil())
7585

76-
g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobDeploymentStatus, Equal(rayv1.JobDeploymentStatusComplete)))
86+
LogWithTimestamp(test.T(), "Waiting for RayCluster %s/%s to be ready", namespace.Name, rayJob.Status.RayClusterName)
87+
g.Eventually(RayCluster(test, namespace.Name, rayJob.Status.RayClusterName), TestTimeoutMedium).
88+
Should(WithTransform(RayClusterState, Equal(rayv1.Ready)))
89+
rayCluster, err := GetRayCluster(test, namespace.Name, rayJob.Status.RayClusterName)
90+
g.Expect(err).NotTo(HaveOccurred())
7791

78-
g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))
79-
})
92+
// Check if the RayCluster created correct number of pods
93+
var desiredWorkerPods int32
94+
if rayCluster.Spec.WorkerGroupSpecs != nil {
95+
for _, workerGroupSpec := range rayCluster.Spec.WorkerGroupSpecs {
96+
desiredWorkerPods += (*workerGroupSpec.Replicas * workerGroupSpec.NumOfHosts)
97+
}
8098
}
99+
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(HaveLen(int(desiredWorkerPods)))
100+
g.Expect(GetRayCluster(test, namespace.Name, rayCluster.Name)).To(WithTransform(RayClusterDesiredWorkerReplicas, Equal(desiredWorkerPods)))
101+
102+
// Check if the head pod is ready
103+
g.Eventually(HeadPod(test, rayCluster), TestTimeoutShort).Should(WithTransform(IsPodRunningAndReady, BeTrue()))
104+
105+
// Check if all worker pods are ready
106+
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(WithTransform(AllPodsRunningAndReady, BeTrue()))
81107
}

0 commit comments

Comments
 (0)