Add backend capability cache reset helper for jail service tests

This commit is contained in:
2026-04-14 10:24:14 +02:00
parent 41a67d52ab
commit cee5372690
3 changed files with 17 additions and 3 deletions

View File

@@ -466,6 +466,8 @@ Imports for side effects are an anti-pattern that creates hidden startup depende
### Task 16 — Reset _backend_cmd_supported between test runs
**Status:** Completed
**Severity:** Medium
**Where:**

View File

@@ -248,6 +248,18 @@ async def _check_backend_cmd_supported(
return _backend_cmd_supported
async def _reset_backend_capability_cache() -> None:
"""Reset the cached backend/idle capability detection state.
This helper is intended for test isolation and for any scenario where the
cached probe result must be invalidated before the next detection attempt.
"""
global _backend_cmd_supported
async with _backend_cmd_lock:
_backend_cmd_supported = None
# ---------------------------------------------------------------------------
# Public API — Jail listing & detail
# ---------------------------------------------------------------------------

View File

@@ -192,7 +192,7 @@ class TestListJails:
fail2ban log.
"""
# Reset the capability cache to test detection.
jail_service._backend_cmd_supported = None
await jail_service._reset_backend_capability_cache()
responses = {
"status": _make_global_status("sshd"),
@@ -217,7 +217,7 @@ class TestListJails:
async def test_backend_idle_commands_supported(self) -> None:
"""list_jails detects and sends backend/idle commands when supported."""
# Reset the capability cache to test detection.
jail_service._backend_cmd_supported = None
await jail_service._reset_backend_capability_cache()
responses = {
"status": _make_global_status("sshd"),
@@ -243,7 +243,7 @@ class TestListJails:
async def test_backend_idle_commands_cached_after_first_probe(self) -> None:
"""list_jails caches capability result and reuses it across polling cycles."""
# Reset the capability cache.
jail_service._backend_cmd_supported = None
await jail_service._reset_backend_capability_cache()
responses = {
"status": _make_global_status("sshd, nginx"),