Ejemplo n.º 1
0
    def deploy_and_check_responses(self,
                                   deployments,
                                   responses,
                                   blocking=True,
                                   client=None):
        """
        Helper function that deploys the list of deployments, calls them with
        their handles, and checks whether they return the objects in responses.
        If blocking is False, this function uses a non-blocking deploy and uses
        the client to wait until the deployments finish deploying.
        """

        deploy_group(deployments, _blocking=blocking)

        def check_all_deployed():
            try:
                for deployment, response in zip(deployments, responses):
                    if ray.get(deployment.get_handle().remote()) != response:
                        return False
            except Exception:
                return False

            return True

        if blocking:
            # If blocking, this should be guaranteed to pass immediately.
            assert check_all_deployed()
        else:
            # If non-blocking, this should pass eventually.
            wait_for_condition(check_all_deployed)
Ejemplo n.º 2
0
    def test_invalid_input(self, serve_instance):
        """
        Checks deploy_group's behavior when deployment group contains
        non-Deployment objects.
        """

        with pytest.raises(TypeError):
            deploy_group([self.f, self.C, "not a Deployment object"])
Ejemplo n.º 3
0
    async def put_all_deployments(self, req: Request) -> Response:
        serve_application_text = await req.text()
        serve_application_schema = ServeApplicationSchema.parse_raw(
            serve_application_text, content_type="application/json")
        deployments = schema_to_serve_application(serve_application_schema)

        deploy_group(deployments, _blocking=False)

        new_names = set()
        for deployment in serve_application_schema.deployments:
            new_names.add(deployment.name)

        all_deployments = serve.list_deployments()
        all_names = set(all_deployments.keys())
        names_to_delete = all_names.difference(new_names)
        for name in names_to_delete:
            all_deployments[name].delete()

        return Response()
Ejemplo n.º 4
0
    def test_mutual_handles(self, serve_instance):
        """
        Atomically deploys a group of deployments that get handles to other
        deployments in the group inside their __init__ functions. The handle
        references should fail in a non-atomic deployment. Checks whether the
        deployments deploy correctly.
        """
        @serve.deployment
        class MutualHandles:
            async def __init__(self, handle_name):
                self.handle = serve.get_deployment(handle_name).get_handle()

            async def __call__(self, echo: str):
                return await self.handle.request_echo.remote(echo)

            async def request_echo(self, echo: str):
                return echo

        names = []
        for i in range(10):
            names.append("a" * i)

        deployments = []
        for idx in range(len(names)):
            # Each deployment will hold a ServeHandle with the next name in
            # the list
            deployment_name = names[idx]
            handle_name = names[(idx + 1) % len(names)]

            deployments.append(
                MutualHandles.options(name=deployment_name,
                                      init_args=(handle_name, )))

        deploy_group(deployments)

        for deployment in deployments:
            assert (ray.get(
                deployment.get_handle().remote("hello"))) == "hello"
Ejemplo n.º 5
0
    def deploy_and_check_responses(self,
                                   deployments,
                                   responses,
                                   blocking=True,
                                   client=None):
        """
        Helper function that deploys the list of deployments, calls them with
        their handles, and checks whether they return the objects in responses.
        If blocking is False, this function uses a non-blocking deploy and uses
        the client to wait until the deployments finish deploying.
        """

        goal_ids = deploy_group(deployments, _blocking=blocking)

        if blocking:
            assert len(goal_ids) == 0
        else:
            assert len(goal_ids) == len(deployments)
            if client:
                for id in goal_ids:
                    client._wait_for_goal(id)

        for deployment, response in zip(deployments, responses):
            assert ray.get(deployment.get_handle().remote()) == response