test: fix templates paths, CLI gating, and stress-suite harness

- tests/**: update templates/ → decnet/templates/ paths after module move
- tests/mysql_spinup.sh: use root:root and asyncmy driver
- tests/test_auto_spawn.py: patch decnet.cli.utils._pid_dir (package split)
- tests/test_cli.py: set DECNET_MODE=master in api-command tests
- tests/stress/conftest.py: run locust out-of-process via its CLI + CSV
  stats shim to avoid urllib3 RecursionError from late gevent monkey-patch;
  raise uvicorn startup timeout to 60s, accept 401 from auth-gated health,
  strip inherited DECNET_* env, surface stderr on 0-request runs
- tests/stress/test_stress.py: loosen baseline thresholds to match hw
This commit is contained in:
2026-04-19 23:50:53 -04:00
parent 262a84ca53
commit 195580c74d
22 changed files with 219 additions and 60 deletions

View File

@@ -71,7 +71,8 @@ def test_pid_file_parent_is_created(fake_popen, tmp_path):
def test_agent_autospawns_forwarder(fake_popen, monkeypatch, tmp_path):
"""`decnet agent` calls _spawn_detached once with a forwarder argv."""
# Isolate PID dir to tmp_path so the test doesn't touch /opt/decnet.
monkeypatch.setattr(fake_popen, "_pid_dir", lambda: tmp_path)
from decnet.cli import utils as _cli_utils
monkeypatch.setattr(_cli_utils, "_pid_dir", lambda: tmp_path)
# Set master host so the auto-spawn branch fires.
monkeypatch.setenv("DECNET_SWARM_MASTER_HOST", "10.0.0.1")
monkeypatch.setenv("DECNET_SWARM_SYSLOG_PORT", "6514")
@@ -103,7 +104,8 @@ def test_agent_autospawns_forwarder(fake_popen, monkeypatch, tmp_path):
def test_agent_no_forwarder_flag_suppresses_spawn(fake_popen, monkeypatch, tmp_path):
monkeypatch.setattr(fake_popen, "_pid_dir", lambda: tmp_path)
from decnet.cli import utils as _cli_utils
monkeypatch.setattr(_cli_utils, "_pid_dir", lambda: tmp_path)
monkeypatch.setenv("DECNET_SWARM_MASTER_HOST", "10.0.0.1")
from decnet.agent import server as _agent_server
monkeypatch.setattr(_agent_server, "run", lambda *a, **k: 0)
@@ -121,7 +123,8 @@ def test_agent_no_forwarder_flag_suppresses_spawn(fake_popen, monkeypatch, tmp_p
def test_agent_skips_forwarder_when_master_unset(fake_popen, monkeypatch, tmp_path):
"""If DECNET_SWARM_MASTER_HOST is not set, auto-spawn is silently
skipped — we don't know where to ship logs to."""
monkeypatch.setattr(fake_popen, "_pid_dir", lambda: tmp_path)
from decnet.cli import utils as _cli_utils
monkeypatch.setattr(_cli_utils, "_pid_dir", lambda: tmp_path)
monkeypatch.delenv("DECNET_SWARM_MASTER_HOST", raising=False)
from decnet.agent import server as _agent_server
monkeypatch.setattr(_agent_server, "run", lambda *a, **k: 0)
@@ -173,7 +176,8 @@ def fake_swarmctl_popen(monkeypatch):
def test_swarmctl_autospawns_listener(fake_swarmctl_popen, monkeypatch, tmp_path):
cli_mod, calls = fake_swarmctl_popen
monkeypatch.setattr(cli_mod, "_pid_dir", lambda: tmp_path)
from decnet.cli import utils as _cli_utils
monkeypatch.setattr(_cli_utils, "_pid_dir", lambda: tmp_path)
monkeypatch.setenv("DECNET_LISTENER_HOST", "0.0.0.0")
monkeypatch.setenv("DECNET_SWARM_SYSLOG_PORT", "6514")
@@ -194,7 +198,8 @@ def test_swarmctl_autospawns_listener(fake_swarmctl_popen, monkeypatch, tmp_path
def test_swarmctl_no_listener_flag_suppresses_spawn(fake_swarmctl_popen, monkeypatch, tmp_path):
cli_mod, calls = fake_swarmctl_popen
monkeypatch.setattr(cli_mod, "_pid_dir", lambda: tmp_path)
from decnet.cli import utils as _cli_utils
monkeypatch.setattr(_cli_utils, "_pid_dir", lambda: tmp_path)
from typer.testing import CliRunner
runner = CliRunner()