Пример #1
0
    def test_valid_serve_application_status_schema(self):
        # Ensure a valid ServeApplicationStatusSchema can be generated

        serve_application_status_schema = {
            "deployment_1": {
                "status": "HEALTHY",
                "message": ""
            },
            "deployment_2": {
                "status": "UNHEALTHY",
                "message": "this deployment is deeply unhealthy",
            },
        }

        serve_application_status_to_schema(serve_application_status_schema)
Пример #2
0
    def test_extra_fields_invalid_serve_application_status_schema(self):
        # Undefined fields should be forbidden in the schema

        serve_application_status_schema = (
            self.get_valid_serve_application_status_schema())

        # Schema should be createable with valid fields
        serve_application_status_to_schema(serve_application_status_schema)

        # Schema should raise error when a nonspecified field is included
        with pytest.raises(ValidationError):
            statuses = [
                status_info_to_schema(name, status_info) for name, status_info
                in serve_application_status_schema.items()
            ]
            ServeApplicationStatusSchema(statuses=statuses, fake_field=None)
Пример #3
0
 async def get_all_deployment_statuses(self, req: Request) -> Response:
     serve_application_status_schema = serve_application_status_to_schema(
         get_deployment_statuses())
     return Response(
         text=serve_application_status_schema.json(),
         content_type="application/json",
     )
Пример #4
0
def test_serve_application_to_schema_to_serve_application():
    @serve.deployment(
        num_replicas=1,
        route_prefix="/hello",
    )
    def f1():
        # The body of this function doesn't matter. See the comment in
        # test_deployment_to_schema_to_deployment.
        pass

    @serve.deployment(
        num_replicas=2,
        route_prefix="/hi",
    )
    def f2():
        pass

    f1._func_or_class = "ray.dashboard.modules.serve.tests.test_schema.global_f"
    f2._func_or_class = "ray.dashboard.modules.serve.tests.test_schema.global_f"

    deployments = schema_to_serve_application(
        serve_application_to_schema([f1, f2]))

    assert deployments[0].num_replicas == 1
    assert deployments[0].route_prefix == "/hello"
    assert deployments[1].num_replicas == 2
    assert deployments[1].route_prefix == "/hi"

    serve.start()

    deployments[0].deploy()
    deployments[1].deploy()
    assert ray.get(deployments[0].get_handle().remote()) == "Hello world!"
    assert requests.get("http://localhost:8000/hello").text == "Hello world!"
    assert ray.get(deployments[1].get_handle().remote()) == "Hello world!"
    assert requests.get("http://localhost:8000/hi").text == "Hello world!"

    # Check statuses
    statuses = serve_application_status_to_schema(
        get_deployment_statuses()).statuses
    deployment_names = {"f1", "f2"}
    for deployment_status in statuses:
        assert deployment_status.status in {"UPDATING", "HEALTHY"}
        assert deployment_status.name in deployment_names
        deployment_names.remove(deployment_status.name)
    assert len(deployment_names) == 0

    serve.shutdown()
Пример #5
0
    def test_valid_serve_application_status_schema(self):
        # Ensure a valid ServeApplicationStatusSchema can be generated

        serve_application_status_schema = (
            self.get_valid_serve_application_status_schema())
        serve_application_status_to_schema(serve_application_status_schema)