Skip to content

[serve] Add docs on best practices for testing #44464

@edoakes

Description

@edoakes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issue, but not time-criticalenhancementRequest for new feature and/or capabilityserveRay Serve Related Issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions