|
5 | 5 | "testing"
|
6 | 6 |
|
7 | 7 | . "github.com/onsi/gomega"
|
| 8 | + corev1 "k8s.io/api/core/v1" |
8 | 9 |
|
9 | 10 | rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
10 | 11 | . "github.com/ray-project/kuberay/ray-operator/test/support"
|
@@ -33,49 +34,74 @@ func TestRayJob(t *testing.T) {
|
33 | 34 | test := With(t)
|
34 | 35 | g := NewWithT(t)
|
35 | 36 | g.ConfigureWithT(WithRayJobResourceLogger(test))
|
36 |
| - |
37 | 37 | yamlFilePath := path.Join(GetSampleYAMLDir(test), tt.name)
|
38 | 38 | namespace := test.NewTestNamespace()
|
39 | 39 | rayJobFromYaml := DeserializeRayJobYAML(test, yamlFilePath)
|
40 | 40 | KubectlApplyYAML(test, yamlFilePath, namespace.Name)
|
41 | 41 |
|
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) |
45 | 43 |
|
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 | +} |
49 | 49 |
|
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 | + } |
53 | 58 |
|
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 | +} |
59 | 72 |
|
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()) |
69 | 77 |
|
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()))) |
72 | 81 |
|
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()) |
75 | 85 |
|
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()) |
77 | 91 |
|
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 | + } |
80 | 98 | }
|
| 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())) |
81 | 107 | }
|
0 commit comments