code: def test_stress_agents_reconnect(
      steps: int, num_agents: int, should_disconnect: bool
  ) -> None:
      random.seed(42)
      master_host = "localhost"
      master_port = "8080"
      cluster_name = "test_stress_agents_reconnect"
      master_name = f"{cluster_name}_determined-master_1"
      conf.MASTER_IP = master_host
      conf.MASTER_PORT = master_port
      master_up(["--master-name", master_name])
  
      # Start all agents.
      agents_are_up = [True] * num_agents
      for i in range(num_agents):
          agent_up(["--agent-name", f"agent-{i}"])
      time.sleep(10)
  
      for step in range(steps):
          print("================ step", step)
          for agent_id, agent_is_up in enumerate(agents_are_up):
              if random.choice(
                  [True, False]
              ):  # Flip agents status randomly.
                  continue
  
              if should_disconnect:
                  # Can't just randomly deploy up/down due to just getting a Docker name conflict.
                  if agent_is_up:
                      agent_down(["--agent-name", f"agent-{agent_id}"])
                  else:
                      agent_up(["--agent-name", f"agent-{agent_id}"])
                  agents_are_up[agent_id] = not agents_are_up[agent_id]
              else:
                  if random.choice([True, False]):
                      agent_disable([f"agent-{agent_id}"])
                      agents_are_up[agent_id] = False
                  else:
                      agent_enable([f"agent-{agent_id}"])
                      agents_are_up[agent_id] = True
          print("agents_are_up:", agents_are_up)
          time.sleep(10)
  
          # Validate that our master kept track of the agent reconnect spam.
          agent_list = json.loads(
              subprocess.check_output(
                  [
                      "det",
                      "agent",
                      "list",
                      "--json",
                  ]
              ).decode()
          )
          print("agent_list:", agent_list)
          assert sum(agents_are_up) <= len(agent_list)
          for agent in agent_list:
              print("agent:", agent)
              agent_id = int(agent["id"].replace("agent-", ""))
              if agents_are_up[agent_id] != agent["enabled"]:
                  p = subprocess.run(
                      [
                          "det",
                          "deploy",
                          "local",
                          "logs",
                      ]
                  )
                  print(p.stdout)
                  print(p.stderr)
              assert (
                  agents_are_up[agent_id] == agent["enabled"]
              ), f"agent is up: {agents_are_up[agent_id]}, agent status: {agent}"
  
          # Can we still schedule something?
          if any(agents_are_up):
              experiment_id = exp.create_experiment(
                  conf.fixtures_path(
                      "no_op/single-one-short-step.yaml"
                  ),
                  conf.fixtures_path("no_op"),
                  None,
              )
              exp.wait_for_experiment_state(
                  experiment_id, bindings.experimentv1State.COMPLETED
              )
  
      for agent_id in range(num_agents):
          agent_down(["--agent-name", f"agent-{agent_id}"])
      master_down(["--master-name", master_name])
  
imports: import json
  import os
  import random
  import subprocess
  import time
  from pathlib import Path
  from typing import List
  import docker
  import pytest
  from determined.common.api import bindings
  from tests import config
  from tests import experiment
  from ..cluster.test_users import logged_in_user
label_desc: Use image node_id 17 for calling a global function with example usage: test_stress_agents_reconnect(steps, num_agents, should_disconnect) without return types