[serve] Fix nonblocking serve.init() (#8068)

This commit is contained in:
Edward Oakes 2020-04-22 11:51:27 -05:00 committed by GitHub
parent 0204dff1e9
commit f9f41e5a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 6 deletions

View file

@ -13,7 +13,7 @@ py_library(
py_test(
name = "test_serve",
size = "medium",
srcs = glob(["tests/*.py"]),
srcs = glob(["tests/*.py"], exclude=["tests/test_nonblocking.py"]),
tags = ["exclusive"],
deps = [":serve_lib"],
)
@ -26,6 +26,14 @@ py_test(
deps = [":serve_lib"]
)
py_test(
name = "test_nonblocking",
size = "small",
srcs = glob(["tests/test_nonblocking.py"]),
tags = ["exclusive"],
deps = [":serve_lib"],
)
# Make sure the example showing in doc is tested
py_test(
name = "quickstart_class",
@ -41,4 +49,4 @@ py_test(
srcs = glob(["examples/doc/*.py"]),
tags = ["exclusive"],
deps = [":serve_lib"]
)
)

View file

@ -26,11 +26,11 @@ class HTTPProxy:
# blocks forever
"""
def __init__(self):
async def fetch_config_from_master(self):
assert ray.is_initialized()
master = ray.util.get_actor(SERVE_MASTER_NAME)
self.route_table, [self.router_handle] = ray.get(
master.get_http_proxy_config.remote())
self.route_table, [self.router_handle
] = await master.get_http_proxy_config.remote()
def set_route_table(self, route_table):
self.route_table = route_table
@ -163,8 +163,9 @@ class HTTPProxy:
@ray.remote
class HTTPProxyActor:
def __init__(self, host, port):
async def __init__(self, host, port):
self.app = HTTPProxy()
await self.app.fetch_config_from_master()
self.host = host
self.port = port

View file

@ -0,0 +1,23 @@
import requests
import sys
from ray import serve
def test_nonblocking():
serve.init()
serve.create_endpoint("endpoint", "/api")
def function(flask_request):
return {"method": flask_request.method}
serve.create_backend(function, "echo:v1")
serve.set_traffic("endpoint", {"echo:v1": 1.0})
resp = requests.get("http://127.0.0.1:8000/api").json()["method"]
assert resp == "GET"
if __name__ == "__main__":
import pytest
sys.exit(pytest.main(["-v", __file__]))