code: def test_active_component_activities(ray_start_with_dashboard):
      # Verify drivers which don't have namespace starting with _ray_internal_
      # are considered active.
  
      webui_url = ray_start_with_dashboard["webui_url"]
      webui_url = format_web_url(webui_url)
  
      driver_template = """
  import ray
  
  ray.init(address="auto", namespace="{namespace}")
  import time
  time.sleep({sleep_time_s})
      """
      run_string_as_driver(
          driver_template.format(
              namespace="my_namespace", sleep_time_s=0
          )
      )
  
      run_string_as_driver_nonblocking(
          driver_template.format(
              namespace="my_namespace", sleep_time_s=5
          )
      )
      run_string_as_driver_nonblocking(
          driver_template.format(
              namespace="_ray_internal_job_info_id1", sleep_time_s=5
          )
      )
      # Simulate the default driver that gets created by dashboard
      run_string_as_driver_nonblocking(
          driver_template.format(
              namespace="_ray_internal_dashboard", sleep_time_s=5
          )
      )
  
      def verify_driver_response():
          # Verify drivers are considered active after running script
          response = requests.get(
              f"{webui_url}/api/component_activities"
          )
          response.raise_for_status()
  
          # Validate schema of response
          data = response.json()
          schema_path = os.path.join(
              os.path.dirname(dashboard.__file__),
              "modules/snapshot/component_activities_schema.json",
          )
  
          jsonschema.validate(
              instance=data, schema=json.load(open(schema_path))
          )
  
          # Validate ray_activity_response field can be cast to RayActivityResponse object
          driver_ray_activity_response = RayActivityResponse(
              **data["driver"]
          )
          print(driver_ray_activity_response)
  
          assert driver_ray_activity_response.is_active == "ACTIVE"
          # Drivers with namespace starting with "_ray_internal" are not
          # considered active drivers. Two active drivers are the second one
          # run with namespace "my_namespace" and the one started
          # from ray_start_with_dashboard
          assert (
              driver_ray_activity_response.reason
              == "Number of active drivers: 2"
          )
  
          return True
  
      wait_for_condition(verify_driver_response)
  
file_path: ray/python/ray/dashboard/modules/snapshot/tests/test_component_activities.py
imports: import os
  import sys
  import json
  import jsonschema
  import pprint
  import pytest
  import requests
  from ray._private.test_utils import format_web_url, run_string_as_driver, run_string_as_driver_nonblocking, wait_for_condition
  from ray.dashboard import dashboard
  from ray.dashboard.consts import RAY_CLUSTER_ACTIVITY_HOOK
  from ray.dashboard.modules.snapshot.snapshot_head import RayActivityResponse
  from ray.dashboard.tests.conftest import *
label_desc: Use image node_id 3 for calling a global function with example usage: test_active_component_activities(ray_start_with_dashboard) and returns: True