code: def test_update_num_replicas(shutdown_ray_and_serve):
      """Test updating num_replicas."""
  
      with ray.init() as ray_context:
  
          @serve.deployment(num_replicas=2)
          def f(*args):
              return "got f"
  
          serve.run(f.bind())
  
          actors = list_actors(
              address=ray_context.address_info["address"],
              filters=[("state", "=", "ALIVE")],
          )
  
          serve.run(f.options(num_replicas=4).bind())
          updated_actors = list_actors(
              address=ray_context.address_info["address"],
              filters=[("state", "=", "ALIVE")],
          )
  
          # Check that only 2 new replicas were created
          assert len(updated_actors) == len(actors) + 2
  
          serve.run(f.options(num_replicas=1).bind())
          updated_actors = list_actors(
              address=ray_context.address_info["address"],
              filters=[("state", "=", "ALIVE")],
          )
  
          # Check that all but 1 replica has spun down
          assert len(updated_actors) == len(actors) - 1
  
imports: import os
  import subprocess
  import sys
  from contextlib import contextmanager
  from tempfile import NamedTemporaryFile
  import pytest
  import requests
  import ray
  import ray._private.state
  import ray.actor
  from ray import serve
  from ray._private.test_utils import wait_for_condition
  from ray.exceptions import RayActorError
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME, SERVE_NAMESPACE
  from ray.serve.context import _get_global_client
  from ray.tests.conftest import call_ray_stop_only
  from ray.util.state import list_actors
label_desc: Use image node_id 8 for calling a global function with example usage: test_update_num_replicas(shutdown_ray_and_serve) and returns: str