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

@@ -1,5 +1,5 @@
"""
Tests for templates/imap/server.py
Tests for decnet/templates/imap/server.py
Exercises the full IMAP4rev1 state machine:
NOT_AUTHENTICATED → AUTHENTICATED → SELECTED
@@ -41,7 +41,7 @@ def _load_imap():
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location(
"imap_server", "templates/imap/server.py"
"imap_server", "decnet/templates/imap/server.py"
)
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/mongodb/server.py
Tests for decnet/templates/mongodb/server.py
Covers the MongoDB wire-protocol (OP_MSG / OP_QUERY) happy path and regression
tests for the zero-length msg_len infinite-loop bug and oversized msg_len.
@@ -24,7 +24,7 @@ def _load_mongodb():
if key in ("mongodb_server", "syslog_bridge"):
del sys.modules[key]
sys.modules["syslog_bridge"] = make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mongodb_server", "templates/mongodb/server.py")
spec = importlib.util.spec_from_file_location("mongodb_server", "decnet/templates/mongodb/server.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/mqtt/server.py
Tests for decnet/templates/mqtt/server.py
Exercises behavior with MQTT_ACCEPT_ALL=1 and customizable topics.
Uses asyncio transport/protocol directly.
@@ -39,7 +39,7 @@ def _load_mqtt(accept_all: bool = True, custom_topics: str = "", persona: str =
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mqtt_server", "templates/mqtt/server.py")
spec = importlib.util.spec_from_file_location("mqtt_server", "decnet/templates/mqtt/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):
spec.loader.exec_module(mod)

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/mqtt/server.py — protocol boundary and fuzz cases.
Tests for decnet/templates/mqtt/server.py — protocol boundary and fuzz cases.
Focuses on the variable-length remaining-length field (MQTT spec: max 4 bytes).
A 5th continuation byte used to cause the server to get stuck waiting for a
@@ -25,7 +25,7 @@ def _load_mqtt():
if key in ("mqtt_server", "syslog_bridge"):
del sys.modules[key]
sys.modules["syslog_bridge"] = make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mqtt_server", "templates/mqtt/server.py")
spec = importlib.util.spec_from_file_location("mqtt_server", "decnet/templates/mqtt/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", {"MQTT_ACCEPT_ALL": "1", "MQTT_PERSONA": "water_plant"}, clear=False):
spec.loader.exec_module(mod)

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/mssql/server.py
Tests for decnet/templates/mssql/server.py
Covers the TDS pre-login / login7 happy path and regression tests for the
zero-length pkt_len infinite-loop bug that was fixed (pkt_len < 8 guard).
@@ -24,7 +24,7 @@ def _load_mssql():
if key in ("mssql_server", "syslog_bridge"):
del sys.modules[key]
sys.modules["syslog_bridge"] = make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mssql_server", "templates/mssql/server.py")
spec = importlib.util.spec_from_file_location("mssql_server", "decnet/templates/mssql/server.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/mysql/server.py
Tests for decnet/templates/mysql/server.py
Covers the MySQL handshake happy path and regression tests for oversized
length fields that could cause huge buffer allocations.
@@ -24,7 +24,7 @@ def _load_mysql():
if key in ("mysql_server", "syslog_bridge"):
del sys.modules[key]
sys.modules["syslog_bridge"] = make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("mysql_server", "templates/mysql/server.py")
spec = importlib.util.spec_from_file_location("mysql_server", "decnet/templates/mysql/server.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/pop3/server.py
Tests for decnet/templates/pop3/server.py
Exercises the full POP3 state machine:
AUTHORIZATION → TRANSACTION
@@ -40,7 +40,7 @@ def _load_pop3():
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location(
"pop3_server", "templates/pop3/server.py"
"pop3_server", "decnet/templates/pop3/server.py"
)
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/postgres/server.py
Tests for decnet/templates/postgres/server.py
Covers the PostgreSQL startup / MD5-auth handshake happy path and regression
tests for zero/tiny/huge msg_len in both the startup and auth states.
@@ -24,7 +24,7 @@ def _load_postgres():
if key in ("postgres_server", "syslog_bridge"):
del sys.modules[key]
sys.modules["syslog_bridge"] = make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("postgres_server", "templates/postgres/server.py")
spec = importlib.util.spec_from_file_location("postgres_server", "decnet/templates/postgres/server.py")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod

View File

@@ -24,7 +24,7 @@ def _load_redis():
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("redis_server", "templates/redis/server.py")
spec = importlib.util.spec_from_file_location("redis_server", "decnet/templates/redis/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):
spec.loader.exec_module(mod)

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/smtp/server.py
Tests for decnet/templates/smtp/server.py
Exercises both modes:
- credential-harvester (SMTP_OPEN_RELAY=0, default)
@@ -43,7 +43,7 @@ def _load_smtp(open_relay: bool):
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("smtp_server", "templates/smtp/server.py")
spec = importlib.util.spec_from_file_location("smtp_server", "decnet/templates/smtp/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):
spec.loader.exec_module(mod)

View File

@@ -1,5 +1,5 @@
"""
Tests for templates/snmp/server.py
Tests for decnet/templates/snmp/server.py
Exercises behavior with SNMP_ARCHETYPE modifications.
Uses asyncio DatagramProtocol directly.
@@ -39,7 +39,7 @@ def _load_snmp(archetype: str = "default"):
sys.modules["syslog_bridge"] = _make_fake_syslog_bridge()
spec = importlib.util.spec_from_file_location("snmp_server", "templates/snmp/server.py")
spec = importlib.util.spec_from_file_location("snmp_server", "decnet/templates/snmp/server.py")
mod = importlib.util.module_from_spec(spec)
with patch.dict("os.environ", env, clear=False):
spec.loader.exec_module(mod)