fastapi and streaming tests use get applications api#53949
Conversation
Signed-off-by: abrar <abrar@anyscale.com>
There was a problem hiding this comment.
Pull Request Overview
This PR updates various tests for FastAPI and streaming responses to use dynamic URL retrieval via the get_application_url(s) API instead of hard-coded localhost URLs.
- Update streaming requester and response tests to use get_application_url.
- Update FastAPI and API tests to build URLs dynamically and remove trailing slashes for consistency.
- Refactor URL construction in the test utilities and adjust message processing in HTTP utilities.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/ray/serve/tests/test_streaming_response.py | Updated streaming tests to construct URLs using get_application_url and support multiple URLs. |
| python/ray/serve/tests/test_fastapi.py | Modified FastAPI and related endpoint tests to use dynamic URL retrieval. |
| python/ray/serve/tests/test_api.py | Revised URL assertions to remove trailing slashes for consistency. |
| python/ray/serve/_private/test_utils.py | Adjusted URL creation logic by trimming trailing slashes. |
| python/ray/serve/_private/http_util.py | Updated message handling logic for processing pickled messages in streamed responses. |
| if isinstance(pickled_messages, bytes): | ||
| messages = pickle.loads(pickled_messages) | ||
| else: | ||
| messages = ( | ||
| pickled_messages | ||
| if isinstance(pickled_messages, list) | ||
| else [pickled_messages] | ||
| ) |
There was a problem hiding this comment.
Consider extracting the message processing logic (handling bytes, list, or single item) into a dedicated helper function to improve readability and maintainability.
| if isinstance(pickled_messages, bytes): | |
| messages = pickle.loads(pickled_messages) | |
| else: | |
| messages = ( | |
| pickled_messages | |
| if isinstance(pickled_messages, list) | |
| else [pickled_messages] | |
| ) | |
| messages = self._process_pickled_messages(pickled_messages) |
| url = f"{target.ip}:{target.port}" | ||
| else: | ||
| raise ValueError(f"Unsupported protocol: {protocol}") | ||
| url = url.rstrip("/") |
There was a problem hiding this comment.
Removing the trailing slash can affect URL consistency when route_prefix is empty; consider adding explicit unit tests to ensure expected behavior under all conditions.
| url = url.rstrip("/") | |
| if route_prefix: | |
| url = url.rstrip("/") |
|
|
||
| r = httpx.get(f"http://localhost:8000{expected_route_prefix}openapi.json") | ||
| url = get_application_url("HTTP") | ||
| assert expected_route_prefix.rstrip("/") in url |
There was a problem hiding this comment.
[nitpick] Using a substring assertion on the URL may lead to false positives if the URL structure changes; consider validating the complete URL format to ensure accuracy.
update serve fastapi and streaming tests Signed-off-by: abrar <abrar@anyscale.com>
update serve fastapi and streaming tests Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
Original PR #53949 by abrarsheikh Original: ray-project/ray#53949
Original PR #53949 by abrarsheikh Original: ray-project/ray#53949
Original PR #53949 by abrarsheikh Original: ray-project/ray#53949
No description provided.