code: def pow_2_scheduler(request) -> PowerOfTwoChoicesReplicaScheduler:
      if not hasattr(request, "param"):
          request.param = {}
  
      # In order to prevent issues like https://github.com/ray-project/ray/issues/40631,
      # construct the scheduler on a different loop to mimic the deployment handle path.
      async def construct_scheduler(loop: asyncio.AbstractEventLoop):
          return PowerOfTwoChoicesReplicaScheduler(
              loop,
              DeploymentID("TEST_DEPLOYMENT", "TEST_APP"),
              prefer_local_node_routing=request.param.get(
                  "prefer_local_node", False
              ),
              prefer_local_az_routing=request.param.get(
                  "prefer_local_az", False
              ),
              self_node_id=SCHEDULER_NODE_ID,
              self_actor_id="fake-actor-id",
              self_availability_zone=request.param.get("az", None),
          )
  
      s = asyncio.new_event_loop().run_until_complete(
          construct_scheduler(get_or_create_event_loop())
      )
  
      # Update the RAY_SERVE_MULTIPLEXED_MODEL_ID_MATCHING_TIMEOUT_S
      # to 0.01s to speed up the test.
      os.environ.update(
          {"RAY_SERVE_MULTIPLEXED_MODEL_ID_MATCHING_TIMEOUT_S": "0.01"}
      )
      importlib.reload(ray.serve._private.constants)
      importlib.reload(ray.serve._private.router)
  
      yield s
  
      # Always verify that all scheduling tasks exit once all queries are satisfied.
      assert s.curr_num_scheduling_tasks == 0
      assert s.num_pending_requests == 0
  
imports: import asyncio
  import importlib
  import os
  import sys
  import time
  from typing import Optional, Set, Tuple, Union
  import pytest
  import ray
  from ray._private.utils import get_or_create_event_loop
  from ray.serve._private.common import DeploymentID
  from ray.serve._private.router import PowerOfTwoChoicesReplicaScheduler, Query, ReplicaWrapper, RequestMetadata
label_desc: Use image node_id 1 for calling a global function with example usage: pow_2_scheduler(request) and returns: PowerOfTwoChoicesReplicaScheduler