code: def check_expected_num_replicas(
      deployment_to_num_replicas: Dict[str, int],
      app_name: str = SERVE_DEFAULT_APP_NAME,
  ) -> bool:
      """Checks that the expected number of replicas for each deployment is running.
  
      Looks for the deployments in the app named app_name.
      """
  
      status = serve.status()
      assert app_name in status.applications
  
      application = status.applications[app_name]
      assert application.status == ApplicationStatus.RUNNING
  
      for name, num_replicas in deployment_to_num_replicas.items():
          assert name in application.deployments
          assert (
              sum(application.deployments[name].replica_states.values())
              == num_replicas
          )
  
      return True
  
imports: import asyncio
  import sys
  from copy import deepcopy
  from typing import Dict, Optional
  import pytest
  import ray
  from ray import serve
  from ray._private.pydantic_compat import BaseModel
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.exceptions import RayActorError
  from ray.serve import Application
  from ray.serve._private.client import ServeControllerClient
  from ray.serve._private.common import ApplicationStatus, DeploymentStatus, DeploymentStatusTrigger, ReplicaState, TargetCapacityDirection
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME, SERVE_NAMESPACE
  from ray.serve.config import AutoscalingConfig
  from ray.serve.context import _get_global_client
  from ray.serve.schema import ServeApplicationSchema, ServeDeploySchema
label_desc: Use image node_id 2 for calling a global function with example usage: check_expected_num_replicas(deployment_to_num_replicas, app_name) and returns: True