code: def test_sweep_scheduler_sweeps_run_and_heartbeat(
      user, sweep_config, num_workers, monkeypatch
  ):
      _patch_wandb_run(monkeypatch)
      monkeypatch.setattr(
          "wandb.sdk.launch.sweeps.scheduler.Scheduler._try_load_executable",
          lambda _: True,
      )
  
      api = internal.Api()
      # Mock agent heartbeat stops after 10 heartbeats
      api.agent_heartbeat = Mock(
          side_effect=[
              [
                  {
                      "type": "run",
                      "run_id": "mock-run-id-1",
                      "args": {"foo_arg": {"value": 1}},
                      "program": "train.py",
                  }
              ]
          ]
          * 10
          + [[{"type": "stop", "run_cap": 7}]]
      )
  
      async def mock_launch_add(*args, **kwargs):
          return Mock(spec=public.QueuedRun)
  
      monkeypatch.setattr(
          "wandb.sdk.launch._launch_add._launch_add",
          mock_launch_add,
      )
  
      def mock_get_run_state(*args, **kwargs):
          if args[2] == "sweep-scheduler":
              return "running"
          return "finished"
  
      api.get_run_state = mock_get_run_state
  
      def mock_stop_run(*args, **kwargs):
          return False
  
      api.stop_run = mock_stop_run
  
      _project = "test-project"
      _job = "test-job:latest"
      sweep_id = wandb.sweep(
          sweep_config, entity=user, project=_project
      )
  
      _scheduler = SweepScheduler(
          api,
          sweep_id=sweep_id,
          entity=user,
          project=_project,
          num_workers=num_workers,
          polling_sleep=0,
          job=_job,
      )
      assert _scheduler.state == SchedulerState.PENDING
      assert _scheduler.is_alive is True
      _scheduler.start()
      assert "mock-run-id-1" not in _scheduler._runs
  
imports: import asyncio
  from typing import Dict
  from unittest.mock import Mock, patch
  import pytest
  import wandb
  from wandb.apis import internal, public
  from wandb.errors import CommError
  from wandb.sdk.launch.sweeps import SchedulerError, load_scheduler
  from wandb.sdk.launch.sweeps.scheduler import RunState, Scheduler, SchedulerState, SweepRun
  from wandb.sdk.launch.sweeps.scheduler_sweep import SweepScheduler
  from wandb.sdk.launch.sweeps.utils import construct_scheduler_args
  from .test_wandb_sweep import VALID_SWEEP_CONFIGS_MINIMAL
label_desc: Use image node_id 13 for calling a global function with example usage: test_sweep_scheduler_sweeps_run_and_heartbeat(user, sweep_config, num_workers, monkeypatch) and returns: Mock, str, False, str