test(live): align mqtt/postgres/mysql live tests with honeypot + loop realities

Three unrelated test-correctness fixes exposed by running tests/live:

- test_mqtt_live: honeypot defaults to auth-required (post-2018
  realistic broker). Anonymous CONNECT is rejected with CONNACK rc=5,
  which the "accept" / "subscribe" tests misread as a failure. Pass
  MQTT_ACCEPT_ALL=1 via a new env= override on the live_service factory
  so only those two tests opt into accept-all.
- test_postgres_live::test_auth_hash_logged: connected with
  dbname='prod', which isn't in the honeypot's per-instance DB list, so
  Postgres (correctly) rejected at startup before asking for a
  password — blowing past the auth event the test asserts on. Target
  'postgres' (always in _BASE_DBS) to reach the auth stage.
- test_mysql_backend_live: the module-scoped mysql_test_db_url fixture
  is bound to the module loop, but function-scoped tests default to
  their own per-function loops. Any reuse of the asyncmy pool then
  tripped "Future attached to a different loop". Pin the whole module
  with pytest.mark.asyncio(loop_scope='module').
This commit is contained in:
2026-04-23 22:06:55 -04:00
parent 26d04d5eb8
commit ae92948e22
4 changed files with 26 additions and 6 deletions

View File

@@ -97,7 +97,7 @@ def assert_rfc5424(
class _ServiceProcess:
"""Manages a live service subprocess and its stdout log queue."""
def __init__(self, service: str, port: int):
def __init__(self, service: str, port: int, extra_env: dict | None = None):
template_dir = _TEMPLATES / service
env = {
**os.environ,
@@ -106,6 +106,8 @@ class _ServiceProcess:
"PYTHONPATH": str(template_dir),
"LOG_TARGET": "",
}
if extra_env:
env.update(extra_env)
self._proc = subprocess.Popen(
[_PYTHON, str(template_dir / "server.py")],
cwd=str(template_dir),
@@ -150,9 +152,9 @@ def live_service() -> Generator:
"""
started: list[_ServiceProcess] = []
def _start(service: str) -> tuple[int, callable]:
def _start(service: str, env: dict | None = None) -> tuple[int, callable]:
port = _free_port()
svc = _ServiceProcess(service, port)
svc = _ServiceProcess(service, port, extra_env=env)
started.append(svc)
if not _wait_for_port(port):
svc.stop()