Skip to content

[doc][serve] Document unit and integration testing patterns - #67288

Merged
abrarsheikh merged 1 commit into
doc-1547-serve-prose-advanced-guidesfrom
doc-1010-serve-testing-patterns
Nov 5, 2026
Merged

abrarsheikh merged 1 commit into
doc-1547-serve-prose-advanced-guidesfrom
doc-1010-serve-testing-patterns

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Description

Stacked on #67069 (Serve advanced guides style pass), because both edit dev-workflow.md. Merge #67069 first, then retarget this PR to master.

Adds a "Write unit and integration tests" section to the Ray Serve development workflow page. It follows the testing approach that Ray Serve maintainers lay out in #44464 and its duplicate #34477:

  • Keep business logic in a plain base class so you can unit test it without Ray, and reach a deployment's underlying class through func_or_class.
  • Integration test by deploying with serve.run, then calling the app through the returned DeploymentHandle (handle.method.remote(...).result()) and over HTTP with requests.

The examples live in a new tested file, doc/source/serve/doc_code/testing_patterns.py, which the existing source/serve/doc_code/**/*.py glob in doc/BUILD.bazel already picks up. FastAPI's TestClient is left out, because the issue says it's untested with Serve. The serve.status() polling pattern is covered separately by #65868 in the contributor guide.

Sources: #44464 and #34477, python/ray/serve/deployment.py (func_or_class), python/ray/serve/api.py (serve.run returns a DeploymentHandle), python/ray/serve/handle.py (DeploymentResponse.result()).

Related issues

Closes #44464

Review notes

  • The snippets show from summarizer import .... The test file makes that import work by registering sys.modules["summarizer"] outside the include markers. Is that acceptable, or should the snippets drop the import lines?
  • The test target binds port 8000, and the serve doc_code targets are tagged exclusive.

Not a duplicate

gh pr list --state open --search "44464 in:body" returns nothing. #65868 is related but documents a different pattern.

Testing

  • python doc/source/serve/doc_code/testing_patterns.py with ray[serve]==2.59.0: 4 passed (test_doubler_class, test_summarize_truncates_text, test_summarize_with_handle, test_summarize_with_http).
  • make -C doc rtd-build: build succeeded. with exit code 0 and no Sphinx warnings.
  • Vale on dev-workflow.md: no errors. ruff check on the new file: clean.

AI assistance

Drafted with AI assistance (Claude Code). The API usage was checked against the Serve source and the example was run locally.

🤖 Generated with Claude Code

@dstrodtman
dstrodtman marked this pull request as ready for review October 22, 2026 16:43
@dstrodtman
dstrodtman requested review from a team as code owners October 22, 2026 16:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new section to the Ray Serve development workflow documentation on writing unit and integration tests, along with a supporting Python file containing the code examples. The review feedback suggests clarifying that for deployments not using @serve.ingress, the handle is called directly via handle.remote(...) instead of handle.<method>.remote(...).


### Integration test with `serve.run`

To test the deployed application, call `serve.run` from a `pytest` fixture. `serve.run` deploys the application and returns a `DeploymentHandle` to the ingress deployment. Call a method with `handle.<method>.remote(...)`, which returns a `DeploymentResponse`, and call `.result()` on the response to wait for the return value. To test the HTTP interface, send requests with an HTTP client such as `requests`. Shut down Serve and Ray when the tests finish:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For deployments that do not use @serve.ingress (such as those using a direct __call__ method), the handle is called directly using handle.remote(...) instead of handle.<method>.remote(...). It would be helpful to clarify this distinction for users who are not using FastAPI/ingress deployments.

@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 22, 2026
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue docs An issue or change related to documentation labels Oct 22, 2026
@dstrodtman
dstrodtman force-pushed the doc-1547-serve-prose-advanced-guides branch from fe41edd to 1b80286 Compare October 30, 2026 16:56
@dstrodtman
dstrodtman requested a review from a team as a code owner October 30, 2026 16:56
Add a "Write unit and integration tests" section to the Serve development
workflow page: keep business logic in a plain base class for Ray-free unit
tests, use the func_or_class property, and test with serve.run through a
DeploymentHandle and over HTTP. Examples live in doc_code/testing_patterns.py.

Closes #44464

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-1010-serve-testing-patterns branch from 4e48a0c to 8a9df0d Compare November 3, 2026 19:09
@abrarsheikh
abrarsheikh merged commit 2e2842e into doc-1547-serve-prose-advanced-guides Nov 5, 2026
6 checks passed
@abrarsheikh
abrarsheikh deleted the doc-1010-serve-testing-patterns branch November 5, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants