test(host_agent): update existing collector tests for new agent API
collect_cpu now returns (aggregate, [per_core]) and build_sample takes a rate-state dict, so the pre-existing tests that asserted the old float return / no-state signature needed updating. Mocks the new collectors (temps/psi/net/diskio) for determinism. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,14 +9,19 @@ def test_build_sample_shape():
|
||||
fake_load = {"1m": 0.1, "5m": 0.2, "15m": 0.3}
|
||||
fake_storage = [{"mount": "/", "total_bytes": 1000, "used_bytes": 400}]
|
||||
|
||||
with patch.object(a, "collect_cpu", return_value=12.5), \
|
||||
with patch.object(a, "collect_cpu", return_value=(12.5, [12.0, 13.0])), \
|
||||
patch.object(a, "collect_memory", return_value=fake_mem), \
|
||||
patch.object(a, "collect_load", return_value=fake_load), \
|
||||
patch.object(a, "collect_uptime", return_value=1234), \
|
||||
patch.object(a, "collect_storage", return_value=fake_storage):
|
||||
sample = a.build_sample(mounts=["/"])
|
||||
patch.object(a, "collect_storage", return_value=fake_storage), \
|
||||
patch.object(a, "collect_temps", return_value=[]), \
|
||||
patch.object(a, "collect_psi", return_value={}), \
|
||||
patch.object(a, "collect_net_raw", return_value={}), \
|
||||
patch.object(a, "collect_diskio_raw", return_value={}):
|
||||
sample = a.build_sample(["/"], {})
|
||||
|
||||
assert sample["cpu_pct"] == 12.5
|
||||
assert sample["cpu_cores"] == [12.0, 13.0]
|
||||
assert sample["mem"]["used_bytes"] == 40
|
||||
assert sample["load"]["1m"] == 0.1
|
||||
assert sample["uptime_secs"] == 1234
|
||||
@@ -36,8 +41,12 @@ def test_build_sample_tolerates_collector_failure():
|
||||
"available_bytes": 1, "swap_used_bytes": 0}), \
|
||||
patch.object(a, "collect_load", return_value={"1m": 0.0, "5m": 0.0, "15m": 0.0}), \
|
||||
patch.object(a, "collect_uptime", return_value=0), \
|
||||
patch.object(a, "collect_storage", return_value=[]):
|
||||
sample = a.build_sample(mounts=["/"])
|
||||
patch.object(a, "collect_storage", return_value=[]), \
|
||||
patch.object(a, "collect_temps", return_value=[]), \
|
||||
patch.object(a, "collect_psi", return_value={}), \
|
||||
patch.object(a, "collect_net_raw", return_value={}), \
|
||||
patch.object(a, "collect_diskio_raw", return_value={}):
|
||||
sample = a.build_sample(["/"], {})
|
||||
assert sample["cpu_pct"] is None
|
||||
assert sample["mem"]["total_bytes"] == 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user