code: def test_drain_agent_sched() -> None:
      """
      Start an experiment, drain it. Start a second one and make sure it schedules
      on the second agent *before* the first one has finished.
      """
      slots = _wait_for_slots(2)
      assert len(slots) == 2
  
      exp_id1 = exp.create_experiment(
          conf.fixtures_path("no_op/single-medium-train-step.yaml"),
          conf.fixtures_path("no_op"),
          None,
      )
      exp.wait_for_experiment_workload_progress(exp_id1)
  
      slots = _fetch_slots()
      used_slots = [s for s in slots if s["allocation_id"] != "FREE"]
      assert len(used_slots) == 1
      agent_id1 = used_slots[0]["agent_id"]
  
      with _disable_agent(agent_id1, drain=True):
          exp_id2 = exp.create_experiment(
              conf.fixtures_path("no_op/single-medium-train-step.yaml"),
              conf.fixtures_path("no_op"),
              None,
          )
          exp.wait_for_experiment_state(
              exp_id2, experimentv1State.RUNNING
          )
  
          # Wait for a state when *BOTH* experiments are scheduled.
          for _ in range(20):
              slots = _fetch_slots()
              assert len(slots) == 2
              used_slots = [
                  s for s in slots if s["allocation_id"] != "FREE"
              ]
              if len(used_slots) == 2:
                  # All good.
                  break
          else:
              pytest.fail(
                  "Second experiment didn't schedule on the second agent "
                  "while the first agent was draining"
              )
  
          exp.wait_for_experiment_state(
              exp_id1, experimentv1State.COMPLETED
          )
          exp.wait_for_experiment_state(
              exp_id2, experimentv1State.COMPLETED
          )
  
          trials1 = exp.experiment_trials(exp_id1)
          trials2 = exp.experiment_trials(exp_id2)
          assert len(trials1) == len(trials2) == 1
          assert (
              len(trials1[0].workloads)
              == len(trials2[0].workloads)
              == 7
          )
  
imports: import contextlib
  import json
  import subprocess
  import time
  from typing import Any, Dict, Iterator, List, Optional, cast
  import pytest
  from determined.common.api.bindings import experimentv1State, get_GetSlot
  from tests import api_utils
  from tests import config
  from tests import experiment
  from .test_users import logged_in_user
  from .utils import assert_command_succeeded, run_zero_slot_command, wait_for_command_state
label_desc: Use image node_id 8 for calling a global function with example usage: test_drain_agent_sched() without return types