code: def test_app_deploy_failed_and_recover(mocked_application_state):
      """Test DEPLOYING -> DEPLOY_FAILED -> (self recovered) -> RUNNING
  
      If while the application is deploying a deployment becomes unhealthy,
      the app is marked as deploy failed. But if the deployment recovers,
      the application status should update to running.
      """
      app_state, deployment_state_manager = mocked_application_state
      deployment_id = DeploymentID("d1", "test_app")
      app_state.deploy({"d1": deployment_info("d1")})
      assert app_state.status == ApplicationStatus.DEPLOYING
  
      # Before status of deployment changes, app should still be DEPLOYING
      app_state.update()
      assert app_state.status == ApplicationStatus.DEPLOYING
  
      # Mark deployment unhealthy -> app should be DEPLOY_FAILED
      deployment_state_manager.set_deployment_unhealthy(deployment_id)
      app_state.update()
      assert app_state.status == ApplicationStatus.DEPLOY_FAILED
      app_state.update()
      assert app_state.status == ApplicationStatus.DEPLOY_FAILED
  
      # Deployment recovers to healthy -> app should be RUNNING
      deployment_state_manager.set_deployment_healthy(deployment_id)
      app_state.update()
      assert app_state.status == ApplicationStatus.RUNNING
      app_state.update()
      assert app_state.status == ApplicationStatus.RUNNING
  
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 7 for calling a global function with example usage: test_app_deploy_failed_and_recover(mocked_application_state) without return types