code: def test_num_clients(init_and_serve_lazy):
      # Tests num clients reporting; useful if you want to build an app that
      # load balances clients between Ray client servers.
  
      def get_job_id(api):
          return api.get_runtime_context().worker.current_job_id
  
      api1 = _ClientContext()
      info1 = api1.connect("localhost:50051")
      job_id_1 = get_job_id(api1)
      assert info1["num_clients"] == 1, info1
      api2 = _ClientContext()
      info2 = api2.connect("localhost:50051")
      job_id_2 = get_job_id(api2)
      assert info2["num_clients"] == 2, info2
  
      assert job_id_1 == job_id_2
  
      # Disconnect the first two clients.
      api1.disconnect()
      api2.disconnect()
      time.sleep(1)
  
      api3 = _ClientContext()
      info3 = api3.connect("localhost:50051")
      job_id_3 = get_job_id(api3)
      assert info3["num_clients"] == 1, info3
      assert job_id_1 != job_id_3
  
      # Check info contains ray and python version.
      assert isinstance(info3["ray_version"], str), info3
      assert isinstance(info3["ray_commit"], str), info3
      assert isinstance(info3["python_version"], str), info3
      assert isinstance(info3["protocol_version"], str), info3
      api3.disconnect()
  
imports: import pytest
  import time
  import random
  import sys
  import subprocess
  from unittest.mock import patch
  import ray.util.client.server.server
  import ray.core.generated.ray_client_pb2
  from ray.util.client import _ClientContext, CURRENT_PROTOCOL_VERSION
  from ray.cluster_utils import cluster_not_supported
  import ray
label_desc: Use image node_id 7 for calling a global function with example usage: test_num_clients(init_and_serve_lazy) and returns: api