code: def test_handle_cache_out_of_scope(serve_instance):
      # https://github.com/ray-project/ray/issues/18980
      initial_num_cached = len(_get_global_client().handle_cache)
  
      @serve.deployment(name="f")
      def f():
          return "hi"
  
      handle = serve.run(f.bind(), name="app")
  
      handle_cache = _get_global_client().handle_cache
      assert len(handle_cache) == initial_num_cached + 1
  
      def sender_where_handle_goes_out_of_scope():
          f = _get_global_client().get_handle(
              "f", "app", missing_ok=True, sync=True
          )
          assert f is handle
          assert f.remote().result() == "hi"
  
      [sender_where_handle_goes_out_of_scope() for _ in range(30)]
      assert len(handle_cache) == initial_num_cached + 1
  
imports: import asyncio
  import gc
  import sys
  import numpy
  import pytest
  import requests
  from fastapi import FastAPI
  from fastapi.responses import JSONResponse
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor
  from ray.serve.context import _get_global_client
  from ray.serve.handle import DeploymentHandle
label_desc: Use image node_id 7 for calling a global function with example usage: test_handle_cache_out_of_scope(serve_instance) and returns: str