Skip to content

Commit

Permalink
fix serve start namespace issue and add test (#16291)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoakes authored and Mingwei Tian committed Jun 7, 2021
1 parent 4e89f65 commit 3a09c82
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/ray/serve/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions python/ray/serve/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
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.")
Expand Down
31 changes: 31 additions & 0 deletions python/ray/serve/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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__]))

0 comments on commit 3a09c82

Please sign in to comment.