ray icon indicating copy to clipboard operation
ray copied to clipboard

[serve] Add docs on best practices for testing

Open edoakes opened this issue 2 years ago • 1 comments

Copy-pasting from what I told a user:

I’d suggest structuring your application like this:

class MyModel:
    # Implement logic here.
    ...

@serve.deployment(...)
class MyModelDeployment(MyModel):
    # Define fastapi routes here.
    pass

That way you can rewrite true unit tests against business logic in MyModel. For integration testing, I haven’t tested the fastapi test client, but I don’t think it will work directly. I’d suggest using requests to send HTTP requests after using serve.run to run the app locally. You can also test using Python DeploymentHandle calls like this: handle: ray.serve.handleDeploymentHandle = serve.run(MyModelDeployment.bind()) handle.method.remote().result() # Calls the app method "method" and returns the result.

edoakes avatar Apr 03 '24 21:04 edoakes

Closing: the Development Workflow guide now covers testing with serve.run and handles, serve run over HTTP, local testing mode for unit tests, and remote clusters.

johntaylor-cell avatar Nov 19 '26 00:11 johntaylor-cell