code: def test_is_ready_for_shutdown(mocked_application_state_manager):
      """Test `is_ready_for_shutdown()` returns the correct state.
  
      When shutting down applications before deployments are deleted, application state
      `is_deleted()` should return False and `is_ready_for_shutdown()` should return
      False. When shutting down applications after deployments are deleted, application
      state `is_deleted()` should return True and `is_ready_for_shutdown()` should return
      True.
      """
      (
          app_state_manager,
          deployment_state_manager,
          kv_store,
      ) = mocked_application_state_manager
      app_name = "test_app"
      deployment_name = "d1"
      deployment_id = DeploymentID(deployment_name, app_name)
  
      # DEPLOY application with deployment "d1"
      params = deployment_params(deployment_name)
      app_state_manager.apply_deployment_args(app_name, [params])
      app_state = app_state_manager._application_states[app_name]
      assert app_state.status == ApplicationStatus.DEPLOYING
  
      # Once deployment is healthy, app should be running
      app_state_manager.update()
      assert deployment_state_manager.get_deployment(deployment_id)
      deployment_state_manager.set_deployment_healthy(deployment_id)
      app_state_manager.update()
      assert app_state.status == ApplicationStatus.RUNNING
  
      # When shutting down applications before deployments are deleted, application state
      # `is_deleted()` should return False and `is_ready_for_shutdown()` should return
      # False
      app_state_manager.shutdown()
      assert not app_state.is_deleted()
      assert not app_state_manager.is_ready_for_shutdown()
  
      # When shutting down applications after deployments are deleted, application state
      # `is_deleted()` should return True and `is_ready_for_shutdown()` should return True
      deployment_state_manager.delete_deployment(deployment_id)
      deployment_state_manager.set_deployment_deleted(deployment_id)
      app_state_manager.update()
      assert app_state.is_deleted()
      assert app_state_manager.is_ready_for_shutdown()
  
imports: import sys
  from typing import Dict, List, Tuple
  from unittest.mock import Mock, PropertyMock, patch
  import pytest
  from ray.exceptions import RayTaskError
  from ray.serve._private.application_state import ApplicationState, ApplicationStateManager, override_deployment_info
  from ray.serve._private.common import ApplicationStatus, DeploymentID, DeploymentStatus, DeploymentStatusInfo, DeploymentStatusTrigger
  from ray.serve._private.config import DeploymentConfig, ReplicaConfig
  from ray.serve._private.deploy_utils import deploy_args_to_deployment_info
  from ray.serve._private.deployment_info import DeploymentInfo
  from ray.serve._private.test_utils import MockKVStore
  from ray.serve._private.utils import get_random_string
  from ray.serve.exceptions import RayServeException
  from ray.serve.schema import DeploymentSchema, ServeApplicationSchema
label_desc: Use image node_id 16 for calling a global function with example usage: test_is_ready_for_shutdown(mocked_application_state_manager) without return types