code: def test_system_monitor(test_settings, join_assets, num_keys):
      # - test compatibility mode where we join metrics from individual assets
      #   before publishing them to the interface
      # - test the future default mode where we publish metrics from individual assets
      interface = AssetInterface()
      settings = SettingsStatic(
          test_settings(
              dict(
                  _stats_sample_rate_seconds=0.1,
                  _stats_samples_to_average=2,
                  _stats_join_assets=join_assets,
              )
          ).to_proto()
      )
  
      # todo: refactor this ugliness into a factory
      mock_assets = [MockAsset1, MockAsset2]
  
      with mock.patch.object(
          wandb.sdk.internal.system.assets.asset_registry,
          "_registry",
          mock_assets,
      ):
          system_monitor = SystemMonitor(
              interface=interface,
              settings=settings,
          )
          system_monitor.start()
          time.sleep(1.5)
          system_monitor.finish()
  
      max_num_keys = 0
      while not interface.metrics_queue.empty():
          metric_record = interface.metrics_queue.get()
          # it's tricky to get the timing right, so we are looking at the
          # maximum number of keys we've seen in the queue as it should be == num_keys;
          # sometimes, due to timing we might see less than num_keys
          max_num_keys = max(max_num_keys, len(metric_record))
      assert max_num_keys == num_keys
  
imports: import threading
  import time
  from collections import deque
  from typing import TYPE_CHECKING, Any
  from unittest import mock
  import pytest
  import wandb
  from wandb.sdk.internal.settings_static import SettingsStatic
  from wandb.sdk.internal.system.assets import CPU, GPU, GPUAMD, IPU, TPU, Disk, GPUApple, Memory, Network, Trainium
  from wandb.sdk.internal.system.assets.asset_registry import asset_registry
  from wandb.sdk.internal.system.assets.interfaces import MetricsMonitor
  from wandb.sdk.internal.system.system_monitor import AssetInterface, SystemMonitor
label_desc: Use image node_id 3 for calling a global function with example usage: test_system_monitor(test_settings, join_assets, num_keys) without return types