mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
fix serve start namespace issue and add test (#16291)
This commit is contained in:
parent
4e89f6568e
commit
3a09c82fbf
3 changed files with 48 additions and 2 deletions
|
@ -231,6 +231,14 @@ py_test(
|
|||
deps = [":serve_lib"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "test_cli",
|
||||
size = "small",
|
||||
srcs = serve_tests_srcs,
|
||||
tags = ["exclusive"],
|
||||
deps = [":serve_lib"],
|
||||
)
|
||||
|
||||
# Runs test_api and test_failure with injected failures in the controller.
|
||||
# TODO(simon): Tests are disabled until #11683 is fixed.
|
||||
# py_test(
|
||||
|
|
|
@ -18,8 +18,15 @@ from ray.serve.constants import DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT
|
|||
type=str,
|
||||
help="Address of the running Ray cluster to connect to. "
|
||||
"Defaults to \"auto\".")
|
||||
def cli(address):
|
||||
ray.init(address=address)
|
||||
@click.option(
|
||||
"--namespace",
|
||||
"-n",
|
||||
default="serve",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Ray namespace to connect to. Defaults to \"serve\".")
|
||||
def cli(address, namespace):
|
||||
ray.init(address=address, namespace=namespace)
|
||||
|
||||
|
||||
@cli.command(help="Start a detached Serve instance on the Ray cluster.")
|
||||
|
|
31
python/ray/serve/tests/test_cli.py
Normal file
31
python/ray/serve/tests/test_cli.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ray_start_stop():
|
||||
subprocess.check_output(["ray", "start", "--head"])
|
||||
yield
|
||||
subprocess.check_output(["ray", "stop", "--force"])
|
||||
|
||||
|
||||
def test_start_shutdown(ray_start_stop):
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
subprocess.check_output(["serve", "shutdown"])
|
||||
|
||||
subprocess.check_output(["serve", "start"])
|
||||
subprocess.check_output(["serve", "shutdown"])
|
||||
|
||||
|
||||
def test_start_shutdown_in_namespace(ray_start_stop):
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
subprocess.check_output(["serve", "-n", "test", "shutdown"])
|
||||
|
||||
subprocess.check_output(["serve", "-n", "test", "start"])
|
||||
subprocess.check_output(["serve", "-n", "test", "shutdown"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main(["-v", "-s", __file__]))
|
Loading…
Add table
Reference in a new issue