Skip to content

Commit 3a09c82

Browse files
edoakesMingwei Tian
authored and
Mingwei Tian
committed
fix serve start namespace issue and add test (#16291)
1 parent 4e89f65 commit 3a09c82

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

python/ray/serve/BUILD

+8
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ py_test(
231231
deps = [":serve_lib"],
232232
)
233233

234+
py_test(
235+
name = "test_cli",
236+
size = "small",
237+
srcs = serve_tests_srcs,
238+
tags = ["exclusive"],
239+
deps = [":serve_lib"],
240+
)
241+
234242
# Runs test_api and test_failure with injected failures in the controller.
235243
# TODO(simon): Tests are disabled until #11683 is fixed.
236244
# py_test(

python/ray/serve/scripts.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818
type=str,
1919
help="Address of the running Ray cluster to connect to. "
2020
"Defaults to \"auto\".")
21-
def cli(address):
22-
ray.init(address=address)
21+
@click.option(
22+
"--namespace",
23+
"-n",
24+
default="serve",
25+
required=False,
26+
type=str,
27+
help="Ray namespace to connect to. Defaults to \"serve\".")
28+
def cli(address, namespace):
29+
ray.init(address=address, namespace=namespace)
2330

2431

2532
@cli.command(help="Start a detached Serve instance on the Ray cluster.")

python/ray/serve/tests/test_cli.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import subprocess
2+
import sys
3+
4+
import pytest
5+
6+
7+
@pytest.fixture
8+
def ray_start_stop():
9+
subprocess.check_output(["ray", "start", "--head"])
10+
yield
11+
subprocess.check_output(["ray", "stop", "--force"])
12+
13+
14+
def test_start_shutdown(ray_start_stop):
15+
with pytest.raises(subprocess.CalledProcessError):
16+
subprocess.check_output(["serve", "shutdown"])
17+
18+
subprocess.check_output(["serve", "start"])
19+
subprocess.check_output(["serve", "shutdown"])
20+
21+
22+
def test_start_shutdown_in_namespace(ray_start_stop):
23+
with pytest.raises(subprocess.CalledProcessError):
24+
subprocess.check_output(["serve", "-n", "test", "shutdown"])
25+
26+
subprocess.check_output(["serve", "-n", "test", "start"])
27+
subprocess.check_output(["serve", "-n", "test", "shutdown"])
28+
29+
30+
if __name__ == "__main__":
31+
sys.exit(pytest.main(["-v", "-s", __file__]))

0 commit comments

Comments
 (0)