pull/73/head
parent
699af5d4a1
commit
f6cc0fe281
@ -0,0 +1,54 @@
|
|||||||
|
# ADN DMR Peer Server - alias dictionary health check surfaces fail-closed rejection risk
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from adn_server.infrastructure.bootstrap.peer_server import _log_alias_health
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def test_warns_when_id_tables_empty_and_registration_enforced(caplog) -> None:
|
||||||
|
config = {"_PEER_IDS": {}, "_SUB_IDS": {}, "_LOCAL_SUBSCRIBER_IDS": {}, "GLOBAL": {}}
|
||||||
|
systems_cfg = {"SYSTEM": {"ENABLED": True, "ALLOW_UNREG_ID": False}}
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
_log_alias_health(config, systems_cfg, logger)
|
||||||
|
assert any("ALL EMPTY" in r.message for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_warning_when_unregistered_ids_allowed(caplog) -> None:
|
||||||
|
config = {"_PEER_IDS": {}, "_SUB_IDS": {}, "_LOCAL_SUBSCRIBER_IDS": {}, "GLOBAL": {}}
|
||||||
|
systems_cfg = {"SYSTEM": {"ENABLED": True, "ALLOW_UNREG_ID": True}}
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
_log_alias_health(config, systems_cfg, logger)
|
||||||
|
assert not any("ALL EMPTY" in r.message for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_warning_when_id_tables_populated(caplog) -> None:
|
||||||
|
config = {"_PEER_IDS": {1: "X"}, "_SUB_IDS": {}, "_LOCAL_SUBSCRIBER_IDS": {}, "GLOBAL": {}}
|
||||||
|
systems_cfg = {"SYSTEM": {"ENABLED": True, "ALLOW_UNREG_ID": False}}
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
_log_alias_health(config, systems_cfg, logger)
|
||||||
|
assert not any("ALL EMPTY" in r.message for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
|
def test_warns_when_server_ids_empty_and_validation_enabled(caplog) -> None:
|
||||||
|
config = {
|
||||||
|
"_PEER_IDS": {1: "X"},
|
||||||
|
"_SUB_IDS": {2: "Y"},
|
||||||
|
"_LOCAL_SUBSCRIBER_IDS": {},
|
||||||
|
"_SERVER_IDS": {},
|
||||||
|
"GLOBAL": {"VALIDATE_SERVER_IDS": True},
|
||||||
|
}
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
_log_alias_health(config, {}, logger)
|
||||||
|
assert any("server_ids is EMPTY" in r.message for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
|
def test_disabled_system_does_not_trigger_warning(caplog) -> None:
|
||||||
|
config = {"_PEER_IDS": {}, "_SUB_IDS": {}, "_LOCAL_SUBSCRIBER_IDS": {}, "GLOBAL": {}}
|
||||||
|
systems_cfg = {"SYSTEM": {"ENABLED": False, "ALLOW_UNREG_ID": False}}
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
_log_alias_health(config, systems_cfg, logger)
|
||||||
|
assert not any("ALL EMPTY" in r.message for r in caplog.records)
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
# ADN DMR Peer Server - ALIASES.POLL_INTERVAL_SEC resolution never aborts startup
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from adn_server.infrastructure.bootstrap.peer_server import (
|
||||||
|
_DEFAULT_ALIAS_POLL_INTERVAL_SEC,
|
||||||
|
_resolve_alias_poll_interval,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def test_missing_key_defaults_to_900() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({}, logger) == _DEFAULT_ALIAS_POLL_INTERVAL_SEC
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_string_defaults_to_900() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": ""}, logger) == 900.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_value_is_used() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": 60}, logger) == 60.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_string_value_is_parsed() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": "120"}, logger) == 120.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_numeric_value_falls_back_without_raising() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": "900s"}, logger) == 900.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_zero_falls_back_without_raising() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": 0}, logger) == 900.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_negative_falls_back_without_raising() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": -5}, logger) == 900.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_none_type_falls_back_without_raising() -> None:
|
||||||
|
assert _resolve_alias_poll_interval({"POLL_INTERVAL_SEC": None}, logger) == 900.0
|
||||||
Loading…
Reference in new issue