code: def test_update_max_replicas_per_node(ray_autoscaling_cluster):
      """Test re-deploying a deployment with different max_replicas_per_node."""
  
      ray.init()
  
      @serve.deployment
      class D:
          def __call__(self):
              return "hello"
  
      # Requires 2 worker nodes.
      serve.run(
          D.options(
              num_replicas=3, max_replicas_per_node=2, name="deploy1"
          ).bind(),
          name="app",
      )
  
      assert len(ray.nodes()) == 3
      node_to_deployment_to_num_replicas = (
          get_node_to_deployment_to_num_replicas()
      )
  
      assert len(node_to_deployment_to_num_replicas) == 2
      # One node has 2 replicas and the other has 1 replica.
      for (
          _,
          deployment_to_num_replicas,
      ) in node_to_deployment_to_num_replicas.items():
          assert deployment_to_num_replicas["deploy1"] in {1, 2}
  
      # Redeploy, requires 3 worker nodes.
      serve.run(
          D.options(
              num_replicas=3, max_replicas_per_node=1, name="deploy1"
          ).bind(),
          name="app",
      )
  
      assert len(ray.nodes()) == 4
      node_to_deployment_to_num_replicas = (
          get_node_to_deployment_to_num_replicas()
      )
  
      assert len(node_to_deployment_to_num_replicas) == 3
      for (
          _,
          deployment_to_num_replicas,
      ) in node_to_deployment_to_num_replicas.items():
          # Every node has 1 replica.
          assert deployment_to_num_replicas["deploy1"] == 1
  
file_path: ray/python/ray/serve/tests/test_max_replicas_per_node.py
imports: import sys
  from collections import defaultdict
  import pytest
  import ray
  from ray import serve
  from ray.util.state import list_actors
label_desc: Use image node_id 3 for calling a global function with example usage: test_update_max_replicas_per_node(ray_autoscaling_cluster) and returns: str