mirror of
https://github.com/wassname/ray.git
synced 2026-07-14 11:17:54 +08:00
[Serve] Implement ServeHandle refactoring (#10527)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def test_handle_in_endpoint(serve_instance):
|
||||
client = serve_instance
|
||||
@@ -16,7 +16,7 @@ def test_handle_in_endpoint(serve_instance):
|
||||
client = serve.connect()
|
||||
self.handle = client.get_handle("endpoint1")
|
||||
|
||||
def __call__(self):
|
||||
def __call__(self, _):
|
||||
return ray.get(self.handle.remote())
|
||||
|
||||
client.create_backend("endpoint1:v0", Endpoint1)
|
||||
@@ -36,6 +36,54 @@ def test_handle_in_endpoint(serve_instance):
|
||||
assert requests.get("http://127.0.0.1:8000/endpoint2").text == "hello"
|
||||
|
||||
|
||||
def test_handle_http_args(serve_instance):
|
||||
client = serve_instance
|
||||
|
||||
class Endpoint:
|
||||
def __call__(self, request):
|
||||
return {
|
||||
"args": dict(request.args),
|
||||
"headers": dict(request.headers),
|
||||
"method": request.method,
|
||||
"json": request.json
|
||||
}
|
||||
|
||||
client.create_backend("backend", Endpoint)
|
||||
client.create_endpoint(
|
||||
"endpoint", backend="backend", route="/endpoint", methods=["POST"])
|
||||
|
||||
ground_truth = {
|
||||
"args": {
|
||||
"arg1": "1",
|
||||
"arg2": "2"
|
||||
},
|
||||
"headers": {
|
||||
"X-Custom-Header": "value"
|
||||
},
|
||||
"method": "POST",
|
||||
"json": {
|
||||
"json_key": "json_val"
|
||||
}
|
||||
}
|
||||
|
||||
resp_web = requests.post(
|
||||
"http://127.0.0.1:8000/endpoint?arg1=1&arg2=2",
|
||||
headers=ground_truth["headers"],
|
||||
json=ground_truth["json"]).json()
|
||||
|
||||
handle = client.get_handle("endpoint")
|
||||
resp_handle = ray.get(
|
||||
handle.options(
|
||||
http_method=ground_truth["method"],
|
||||
http_headers=ground_truth["headers"]).remote(
|
||||
ground_truth["json"], **ground_truth["args"]))
|
||||
|
||||
for resp in [resp_web, resp_handle]:
|
||||
for field in ["args", "method", "json"]:
|
||||
assert resp[field] == ground_truth[field]
|
||||
resp["headers"]["X-Custom-Header"] == "value"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user