feat(client): report per-protocol presence in HTB and network_monitor
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uc9V1v7iXruubpoLiSE24M
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from hbd.client.main import build_heartbeat_msg
|
||||
|
||||
|
||||
class _Conn:
|
||||
ackcount = 3
|
||||
rtts = [0, 12.5]
|
||||
|
||||
|
||||
class _Conn2:
|
||||
def __init__(self, flags):
|
||||
self._flags = flags
|
||||
|
||||
def flags(self):
|
||||
return self._flags
|
||||
|
||||
|
||||
def test_heartbeat_without_connectivity_is_unchanged():
|
||||
assert build_heartbeat_msg(_Conn(), 60) == {"acks": 3, "rtt": 12.5, "interval": 60}
|
||||
|
||||
|
||||
def test_heartbeat_carries_presence_flags():
|
||||
msg = build_heartbeat_msg(_Conn(), 60, _Conn2({"p4": True, "p6": False}))
|
||||
assert msg == {"acks": 3, "rtt": 12.5, "interval": 60, "p4": True, "p6": False}
|
||||
|
||||
|
||||
def test_heartbeat_omits_unknown_flags():
|
||||
msg = build_heartbeat_msg(_Conn(), 60, _Conn2({}))
|
||||
assert "p4" not in msg and "p6" not in msg
|
||||
@@ -0,0 +1,26 @@
|
||||
import asyncio
|
||||
|
||||
from hbd.client import connectivity
|
||||
from hbd.client.plugins.network_monitor import NetworkMonitorPlugin
|
||||
|
||||
|
||||
class _FakeShared:
|
||||
def as_metric(self):
|
||||
return {"ipv4": {"present": True, "addr": "192.0.2.5", "gateway": "192.0.2.1", "rtt": 9.0},
|
||||
"ipv6": {"present": False, "addr": None, "gateway": None, "rtt": None}}
|
||||
|
||||
|
||||
def test_collect_includes_connectivity_when_probe_running():
|
||||
connectivity.set_shared(_FakeShared())
|
||||
try:
|
||||
data = asyncio.run(NetworkMonitorPlugin()._collect_metrics())
|
||||
finally:
|
||||
connectivity.set_shared(None)
|
||||
assert data["connectivity"]["ipv4"]["present"] is True
|
||||
assert data["connectivity"]["ipv6"]["present"] is False
|
||||
|
||||
|
||||
def test_collect_omits_connectivity_without_probe():
|
||||
connectivity.set_shared(None)
|
||||
data = asyncio.run(NetworkMonitorPlugin()._collect_metrics())
|
||||
assert "connectivity" not in data
|
||||
Reference in New Issue
Block a user