Add backend capability cache reset helper for jail service tests
This commit is contained in:
@@ -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
|
### Task 16 — Reset _backend_cmd_supported between test runs
|
||||||
|
|
||||||
|
**Status:** Completed
|
||||||
|
|
||||||
**Severity:** Medium
|
**Severity:** Medium
|
||||||
|
|
||||||
**Where:**
|
**Where:**
|
||||||
|
|||||||
@@ -248,6 +248,18 @@ async def _check_backend_cmd_supported(
|
|||||||
return _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
|
# Public API — Jail listing & detail
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ class TestListJails:
|
|||||||
fail2ban log.
|
fail2ban log.
|
||||||
"""
|
"""
|
||||||
# Reset the capability cache to test detection.
|
# Reset the capability cache to test detection.
|
||||||
jail_service._backend_cmd_supported = None
|
await jail_service._reset_backend_capability_cache()
|
||||||
|
|
||||||
responses = {
|
responses = {
|
||||||
"status": _make_global_status("sshd"),
|
"status": _make_global_status("sshd"),
|
||||||
@@ -217,7 +217,7 @@ class TestListJails:
|
|||||||
async def test_backend_idle_commands_supported(self) -> None:
|
async def test_backend_idle_commands_supported(self) -> None:
|
||||||
"""list_jails detects and sends backend/idle commands when supported."""
|
"""list_jails detects and sends backend/idle commands when supported."""
|
||||||
# Reset the capability cache to test detection.
|
# Reset the capability cache to test detection.
|
||||||
jail_service._backend_cmd_supported = None
|
await jail_service._reset_backend_capability_cache()
|
||||||
|
|
||||||
responses = {
|
responses = {
|
||||||
"status": _make_global_status("sshd"),
|
"status": _make_global_status("sshd"),
|
||||||
@@ -243,7 +243,7 @@ class TestListJails:
|
|||||||
async def test_backend_idle_commands_cached_after_first_probe(self) -> None:
|
async def test_backend_idle_commands_cached_after_first_probe(self) -> None:
|
||||||
"""list_jails caches capability result and reuses it across polling cycles."""
|
"""list_jails caches capability result and reuses it across polling cycles."""
|
||||||
# Reset the capability cache.
|
# Reset the capability cache.
|
||||||
jail_service._backend_cmd_supported = None
|
await jail_service._reset_backend_capability_cache()
|
||||||
|
|
||||||
responses = {
|
responses = {
|
||||||
"status": _make_global_status("sshd, nginx"),
|
"status": _make_global_status("sshd, nginx"),
|
||||||
|
|||||||
Reference in New Issue
Block a user