fix serve start namespace issue and add test (#16291)

This commit is contained in:
Edward Oakes 2021-06-07 13:30:31 -05:00 committed by Mingwei Tian
parent 4e89f6568e
commit 3a09c82fbf
No known key found for this signature in database
GPG key ID: 0BE002D6A9F508EB
3 changed files with 48 additions and 2 deletions

View file

@ -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(

View file

@ -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.")

View 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__]))