code: def test_scaling_replicas(serve_instance):
      @serve.deployment(name="counter", num_replicas=2)
      class Counter:
          def __init__(self):
              self.count = 0
  
          def __call__(self, _):
              self.count += 1
              return self.count
  
      serve.run(Counter.bind())
  
      counter_result = []
      for _ in range(10):
          resp = requests.get("http://127.0.0.1:8000/counter").json()
          counter_result.append(resp)
  
      # If the load is shared among two replicas. The max result cannot be 10.
      assert max(counter_result) < 10
  
      serve.run(Counter.options(num_replicas=1).bind())
  
      counter_result = []
      for _ in range(10):
          resp = requests.get("http://127.0.0.1:8000/counter").json()
          counter_result.append(resp)
      # Give some time for a replica to spin down. But majority of the request
      # should be served by the only remaining replica.
      assert max(counter_result) - min(counter_result) > 6
  
imports: import asyncio
  import os
  import sys
  from typing import Dict, Optional
  import pytest
  import requests
  import starlette.responses
  from fastapi import FastAPI
  import ray
  from ray import serve
  from ray._private.pydantic_compat import BaseModel, ValidationError
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.serve._private.api import call_app_builder_with_args_if_necessary
  from ray.serve._private.common import DeploymentID
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
  from ray.serve.deployment import Application
  from ray.serve.exceptions import RayServeException
  from ray.serve.handle import DeploymentHandle, RayServeHandle
label_desc: Use image node_id 15 for calling a global function with example usage: test_scaling_replicas(serve_instance) and returns: self