12
12
)
13
13
14
14
from framework .utils import (
15
+ delete_all_cr ,
15
16
get_head_pod ,
16
17
get_pod ,
17
18
pod_exec_command ,
@@ -86,8 +87,9 @@ class RayFTTestCase(unittest.TestCase):
86
87
cluster_template = CONST .REPO_ROOT .joinpath ("tests/config/ray-cluster.ray-ft.yaml.template" )
87
88
ray_cluster_ns = "default"
88
89
89
- @classmethod
90
- def setUpClass (cls ):
90
+ # We need to delete the RayCluster at the end of each test case to test cleanup_redis,
91
+ # therefore, we use setUp, instead of setUpClass, here to re-create RayCluster for each test case.
92
+ def setUp (self ):
91
93
if not utils .is_feature_supported (ray_version , CONST .RAY_FT ):
92
94
raise unittest .SkipTest (f"{ CONST .RAY_FT } is not supported" )
93
95
K8S_CLUSTER_MANAGER .cleanup ()
@@ -96,6 +98,13 @@ def setUpClass(cls):
96
98
operator_manager .prepare_operator ()
97
99
utils .create_ray_cluster (RayFTTestCase .cluster_template , ray_version , ray_image )
98
100
101
+ def cleanup_redis (self ):
102
+ delete_all_cr (CONST .RAY_CLUSTER_CRD , RayFTTestCase .ray_cluster_ns )
103
+ utils .wait_for_condition (
104
+ lambda : shell_subprocess_run ("test $(kubectl exec deploy/redis -- redis-cli --no-auth-warning -a 5241590000000000 DBSIZE) = '0'" ) == 0 ,
105
+ timeout = 300 , retry_interval_ms = 1000 ,
106
+ )
107
+
99
108
def test_ray_serve (self ):
100
109
"""Kill GCS process on the head Pod and then test a deployed Ray Serve model."""
101
110
if not utils .is_feature_supported (ray_version , CONST .RAY_SERVE_FT ):
@@ -153,6 +162,8 @@ def test_ray_serve(self):
153
162
show_cluster_info (RayFTTestCase .ray_cluster_ns )
154
163
self .fail (f"Fail to execute test_ray_serve_2.py. The exit code is { exit_code } ." )
155
164
165
+ self .cleanup_redis ()
166
+
156
167
@unittest .skipIf (
157
168
ray_version == '2.8.0' ,
158
169
'test_detached_actor is too flaky with Ray 2.8.0 due to '
@@ -233,6 +244,8 @@ def test_detached_actor(self):
233
244
show_cluster_info (RayFTTestCase .ray_cluster_ns )
234
245
self .fail (f"Fail to execute test_detached_actor_2.py. The exit code is { exit_code } ." )
235
246
247
+ self .cleanup_redis ()
248
+
236
249
class KubeRayHealthCheckTestCase (unittest .TestCase ):
237
250
"""Test KubeRay health check"""
238
251
cluster_template = CONST .REPO_ROOT .joinpath ("tests/config/ray-cluster.sidecar.yaml.template" )
0 commit comments