Skip to content

Commit

Permalink
[RayService] Use Ready condition in e2e tests (#2849)
Browse files Browse the repository at this point in the history
Signed-off-by: kaihsun <[email protected]>
  • Loading branch information
kevin85421 authored Jan 28, 2025
1 parent 8f75ad5 commit f7cf955
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
29 changes: 10 additions & 19 deletions ray-operator/test/e2erayservice/rayservice_redeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1"
"github.com/ray-project/kuberay/ray-operator/test/sampleyaml"
Expand All @@ -30,7 +29,7 @@ func TestRedeployRayServe(t *testing.T) {

test.T().Logf("Waiting for RayService %s/%s to running", rayService.Namespace, rayService.Name)
g.Eventually(RayService(test, rayService.Namespace, rayService.Name), TestTimeoutMedium).
Should(WithTransform(RayServiceStatus, Equal(rayv1.Running)))
Should(WithTransform(IsRayServiceReady, BeTrue()))

// Get the latest RayService
rayService, err = GetRayService(test, namespace.Name, rayServiceName)
Expand All @@ -52,14 +51,10 @@ func TestRedeployRayServe(t *testing.T) {
test.T().Logf("Curl pod %s/%s is running and ready", namespace.Name, curlPodName)

test.T().Logf("Sending requests to the RayService to make sure it is ready to serve requests")
g.Eventually(func(g Gomega) {
// curl /fruit
stdout, _ := curlRayServicePod(test, rayService, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
g.Expect(stdout.String()).To(Equal("6"))
// curl /calc
stdout, _ = curlRayServicePod(test, rayService, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
g.Expect(stdout.String()).To(Equal("15 pizzas please!"))
}, TestTimeoutShort).Should(Succeed())
stdout, _ := curlRayServicePod(test, rayService, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
g.Expect(stdout.String()).To(Equal("6"))
stdout, _ = curlRayServicePod(test, rayService, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
g.Expect(stdout.String()).To(Equal("15 pizzas please!"))

test.T().Logf("Deleting the current Head for recreating a new one")
rayServiceUnderlyingRayCluster, err := GetRayCluster(test, namespace.Name, rayService.Status.ActiveServiceStatus.RayClusterName)
Expand All @@ -81,15 +76,11 @@ func TestRedeployRayServe(t *testing.T) {

test.T().Logf("Waiting for RayService %s/%s to running", rayService.Namespace, rayService.Name)
g.Eventually(RayService(test, rayService.Namespace, rayService.Name), TestTimeoutMedium).
Should(WithTransform(RayServiceStatus, Equal(rayv1.Running)))
Should(WithTransform(IsRayServiceReady, BeTrue()))

test.T().Logf("Sending requests to the RayService to make sure it is ready to serve requests")
g.Eventually(func(g Gomega) {
// curl /fruit
stdout, _ := curlRayServicePod(test, rayService, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
g.Expect(stdout.String()).To(Equal("6"))
// curl /calc
stdout, _ = curlRayServicePod(test, rayService, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
g.Expect(stdout.String()).To(Equal("15 pizzas please!"))
}, TestTimeoutShort).Should(Succeed())
stdout, _ = curlRayServicePod(test, rayService, curlPod, curlContainerName, "/fruit", `["MANGO", 2]`)
g.Expect(stdout.String()).To(Equal("6"))
stdout, _ = curlRayServicePod(test, rayService, curlPod, curlContainerName, "/calc", `["MUL", 3]`)
g.Expect(stdout.String()).To(Equal("15 pizzas please!"))
}
5 changes: 5 additions & 0 deletions ray-operator/test/support/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
Expand Down Expand Up @@ -194,6 +195,10 @@ func RayServiceStatus(service *rayv1.RayService) rayv1.ServiceStatus {
return service.Status.ServiceStatus
}

func IsRayServiceReady(service *rayv1.RayService) bool {
return meta.IsStatusConditionTrue(service.Status.Conditions, string(rayv1.RayServiceReady))
}

func RayServicesNumEndPoints(service *rayv1.RayService) int32 {
return service.Status.NumServeEndpoints
}
Expand Down

0 comments on commit f7cf955

Please sign in to comment.