code: def test_named_actor_refcount(ray_start_regular):
      with ray_start_client_server_pair() as (ray, server):
  
          @ray.remote
          class ActorTest:
              def __init__(self):
                  self._counter = 0
  
              def bump(self):
                  self._counter += 1
  
              def check(self):
                  return self._counter
  
          ActorTest.options(name="actor", lifetime="detached").remote()
  
          def connect_api():
              api = _ClientContext()
              api.connect(
                  "localhost:50051", namespace="default_test_namespace"
              )
              api.get_actor("actor")
              return api
  
          def check_owners(size):
              return size == sum(
                  len(x)
                  for x in server.task_servicer.actor_owners.values()
              )
  
          apis = [connect_api() for i in range(3)]
          assert check_owners(3)
          assert len(server.task_servicer.actor_refs) == 1
          assert len(server.task_servicer.named_actors) == 1
  
          apis.pop(0).disconnect()
          assert check_owners(2)
          assert len(server.task_servicer.actor_refs) == 1
          assert len(server.task_servicer.named_actors) == 1
  
          apis.pop(0).disconnect()
          assert check_owners(1)
          assert len(server.task_servicer.actor_refs) == 1
          assert len(server.task_servicer.named_actors) == 1
  
          apis.pop(0).disconnect()
          # no more owners should be seen
          assert check_owners(0)
          # actor refs shouldn't be removed
          assert len(server.task_servicer.actor_refs) == 1
          assert len(server.task_servicer.named_actors) == 1
  
file_path: ray/python/ray/tests/test_client_references.py
imports: from concurrent.futures import Future
  import pytest
  import ray
  from ray._private.test_utils import object_memory_usage, wait_for_condition
  from ray._raylet import ActorID, ObjectRef
  from ray.util.client import _ClientContext
  from ray.util.client.common import ClientActorRef, ClientObjectRef
  from ray.util.client.ray_client_helpers import ray_start_client_server, ray_start_client_server_pair, ray_start_cluster_client_server_pair
label_desc: Use image node_id 10 for calling a global function with example usage: test_named_actor_refcount(ray_start_regular) and returns: api, unknown, self