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

test: add sample yaml rayjob test cases #2487

Merged
merged 6 commits into from
Nov 5, 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
83 changes: 83 additions & 0 deletions ray-operator/test/sampleyaml/rayjob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package sampleyaml

import (
"testing"

. "github.com/onsi/gomega"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
. "github.com/ray-project/kuberay/ray-operator/test/support"
)

func TestRayJob(t *testing.T) {
tests := []struct {
name string
}{
{
name: "ray-job.custom-head-svc.yaml",
},
{
name: "ray-job.modin.yaml",
},
{
name: "ray-job.resources.yaml",
},
{
name: "ray-job.sample.yaml",
},
{
name: "ray-job.shutdown.yaml",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
test := With(t)
g := NewWithT(t)

namespace := test.NewTestNamespace()
test.StreamKubeRayOperatorLogs()
rayJobFromYaml := DeserializeRayJobSampleYAML(test, tt.name)
KubectlApplyYAML(test, tt.name, namespace.Name)

rayJob, err := GetRayJob(test, namespace.Name, rayJobFromYaml.Name)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(rayJob).NotTo(BeNil())

// Wait for RayCluster name to be populated
g.Eventually(RayJob(test, rayJob.Namespace, rayJob.Name), TestTimeoutShort).
Should(WithTransform(RayJobClusterName, Not(BeEmpty())))

rayJob, err = GetRayJob(test, rayJob.Namespace, rayJob.Name)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(rayJob).NotTo(BeNil())

test.T().Logf("Waiting for RayCluster %s/%s to be ready", namespace.Name, rayJob.Status.RayClusterName)
g.Eventually(RayCluster(test, namespace.Name, rayJob.Status.RayClusterName), TestTimeoutMedium).
Should(WithTransform(RayClusterState, Equal(rayv1.Ready)))
rayCluster, err := GetRayCluster(test, namespace.Name, rayJob.Status.RayClusterName)
MortalHappiness marked this conversation as resolved.
Show resolved Hide resolved
MortalHappiness marked this conversation as resolved.
Show resolved Hide resolved
g.Expect(err).NotTo(HaveOccurred())

// Check if the RayCluster created correct number of pods
var desiredWorkerReplicas int32
if rayCluster.Spec.WorkerGroupSpecs != nil {
for _, workerGroupSpec := range rayCluster.Spec.WorkerGroupSpecs {
desiredWorkerReplicas += *workerGroupSpec.Replicas
}
}

g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(HaveLen(int(desiredWorkerReplicas)))
g.Expect(rayCluster.Status.DesiredWorkerReplicas).To(Equal(desiredWorkerReplicas))

// Check if the head pod is ready
g.Eventually(HeadPod(test, rayCluster), TestTimeoutShort).Should(WithTransform(IsPodRunningAndReady, BeTrue()))

// Check if all worker pods are ready
g.Eventually(WorkerPods(test, rayCluster), TestTimeoutShort).Should(WithTransform(AllPodsRunningAndReady, BeTrue()))

g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobDeploymentStatus, Equal(rayv1.JobDeploymentStatusComplete)))

g.Eventually(RayJob(test, namespace.Name, rayJobFromYaml.Name), TestTimeoutMedium).Should(WithTransform(RayJobStatus, Equal(rayv1.JobStatusSucceeded)))
})
}
}
10 changes: 10 additions & 0 deletions ray-operator/test/sampleyaml/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ func DeserializeRayServiceSampleYAML(t Test, filename string) *rayv1.RayService
return rayService
}

func DeserializeRayJobSampleYAML(t Test, filename string) *rayv1.RayJob {
t.T().Helper()
yamlFileContent := readYAML(t, filename)
decoder := rayscheme.Codecs.UniversalDecoder()
rayJob := &rayv1.RayJob{}
_, _, err := decoder.Decode(yamlFileContent, nil, rayJob)
assert.NoError(t.T(), err)
return rayJob
}

func KubectlApplyYAML(t Test, filename string, namespace string) {
t.T().Helper()
sampleYAMLDir := getSampleYAMLDir(t)
Expand Down
4 changes: 4 additions & 0 deletions ray-operator/test/support/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func RayJobSucceeded(job *rayv1.RayJob) int32 {
return *job.Status.Succeeded
}

func RayJobClusterName(job *rayv1.RayJob) string {
return job.Status.RayClusterName
}

func RayCluster(t Test, namespace, name string) func() (*rayv1.RayCluster, error) {
return func() (*rayv1.RayCluster, error) {
return GetRayCluster(t, namespace, name)
Expand Down
Loading