From 9dc625318f51f7d2ccaeb44ca331d94bc3b2a2f7 Mon Sep 17 00:00:00 2001 From: Edward Oakes Date: Fri, 24 Apr 2020 20:15:27 -0500 Subject: [PATCH] [serve] Add basic test for specifying the method in a serve call (#8172) --- python/ray/serve/tests/test_api.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/python/ray/serve/tests/test_api.py b/python/ray/serve/tests/test_api.py index ffb599d60..5b57c91fc 100644 --- a/python/ray/serve/tests/test_api.py +++ b/python/ray/serve/tests/test_api.py @@ -40,6 +40,28 @@ def test_e2e(serve_instance): assert resp == "POST" +def test_call_method(serve_instance): + serve.create_endpoint("call-method", "/call-method") + + class CallMethod: + def method(self, request): + return "hello" + + serve.create_backend(CallMethod, "call-method") + serve.set_traffic("call-method", {"call-method": 1.0}) + + # Test HTTP path. + resp = requests.get( + "http://127.0.0.1:8000/call-method", + timeout=1, + headers={"X-SERVE-CALL-METHOD": "method"}) + assert resp.text == "hello" + + # Test serve handle path. + handle = serve.get_handle("call-method") + assert ray.get(handle.options("method").remote()) == "hello" + + def test_no_route(serve_instance): serve.create_endpoint("noroute-endpoint")