mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 18:43:38 +01:00
Reuse the healthy agent-load smoke window
Validate report identity, increasing per-agent sequences and dashboard traffic in one unchanged timed control instead of three. Require repeated reports for the sequence check and retain every adverse scenario separately. Contract-Neutral: Consolidates identical synthetic test runs and strengthens coverage; no monitoring, CI admission or runtime behavior changes. Change-source: pulse-maintainer
This commit is contained in:
@@ -155,44 +155,48 @@ class AgentLoadTests(unittest.TestCase):
|
||||
])
|
||||
return code, json.loads(stats_path.read_text())
|
||||
|
||||
def test_each_agent_reports_with_its_own_token_and_identity(self):
|
||||
def test_healthy_run_reports_distinct_identities_monotonic_sequences_and_live_state(self):
|
||||
# Observe all three properties in the same unmodified control run,
|
||||
# rather than paying for the same timed load window three times.
|
||||
code, stats = self.drive()
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(len(FakePulse.tokens), 4)
|
||||
hosts = [(token, body) for path, token, body in FakePulse.reports if path.endswith("/agent/report")]
|
||||
docker = [(token, body) for path, token, body in FakePulse.reports if path.endswith("/docker/report")]
|
||||
self.assertGreaterEqual(stats["accepted"]["host"], 4)
|
||||
self.assertEqual(stats["accepted"]["docker"], len(docker))
|
||||
identity = {}
|
||||
for token, body in hosts:
|
||||
identity.setdefault(token, set()).add((body["host"]["hostname"], body["host"]["machineId"]))
|
||||
self.assertEqual(set(identity), set(FakePulse.tokens))
|
||||
self.assertTrue(all(len(pairs) == 1 for pairs in identity.values()))
|
||||
self.assertEqual(len({next(iter(pairs)) for pairs in identity.values()}), 4)
|
||||
self.assertEqual({token for token, _ in docker}, set(FakePulse.tokens[:2]))
|
||||
self.assertTrue(all(len(body["containers"]) == 3 for _, body in docker))
|
||||
|
||||
def test_sequence_ids_increase_per_agent(self):
|
||||
self.drive()
|
||||
by_token = {}
|
||||
for path, token, body in FakePulse.reports:
|
||||
if path.endswith("/agent/report"):
|
||||
by_token.setdefault(token, []).append(int(body["sequenceId"].rsplit(":", 1)[1]))
|
||||
for sequence in by_token.values():
|
||||
self.assertEqual(sequence, sorted(sequence))
|
||||
self.assertEqual(len(set(sequence)), len(sequence))
|
||||
for token, body in hosts:
|
||||
by_token.setdefault(token, []).append(body)
|
||||
|
||||
def test_dashboard_counts_frames_and_answers_pings(self):
|
||||
code, stats = self.drive()
|
||||
self.assertEqual(code, 0)
|
||||
self.assertGreaterEqual(stats["dashboard"]["connects"], 1)
|
||||
self.assertEqual(stats["dashboard"]["messages"], 3)
|
||||
self.assertEqual(stats["dashboard"]["initial_states"], 1)
|
||||
self.assertEqual(stats["dashboard"]["state_updates"], 1)
|
||||
self.assertEqual(stats["dashboard"]["state_messages"], 2)
|
||||
self.assertGreater(stats["dashboard"]["bytes"], stats["dashboard"]["state_bytes"])
|
||||
self.assertIn(bytes([0x8A]) + b"ping", FakePulse.pongs)
|
||||
self.assertFalse(agent_load.DASHBOARD_SOCKETS)
|
||||
with self.subTest("report identity"):
|
||||
self.assertEqual(len(FakePulse.tokens), 4)
|
||||
self.assertEqual(stats["accepted"]["host"], len(hosts))
|
||||
self.assertEqual(stats["accepted"]["docker"], len(docker))
|
||||
identity = {
|
||||
token: {(body["host"]["hostname"], body["host"]["machineId"]) for body in reports}
|
||||
for token, reports in by_token.items()
|
||||
}
|
||||
self.assertEqual(set(identity), set(FakePulse.tokens))
|
||||
self.assertTrue(all(len(pairs) == 1 for pairs in identity.values()))
|
||||
self.assertEqual(len({next(iter(pairs)) for pairs in identity.values()}), 4)
|
||||
self.assertEqual({token for token, _ in docker}, set(FakePulse.tokens[:2]))
|
||||
self.assertTrue(all(len(body["containers"]) == 3 for _, body in docker))
|
||||
|
||||
with self.subTest("report sequence"):
|
||||
self.assertEqual(set(by_token), set(FakePulse.tokens))
|
||||
for token, reports in by_token.items():
|
||||
with self.subTest(token=token):
|
||||
sequence = [int(body["sequenceId"].rsplit(":", 1)[1]) for body in reports]
|
||||
self.assertGreaterEqual(len(sequence), 2, "sequence check needs repeated reports")
|
||||
self.assertEqual(sequence, sorted(set(sequence)))
|
||||
|
||||
with self.subTest("dashboard state"):
|
||||
self.assertGreaterEqual(stats["dashboard"]["connects"], 1)
|
||||
self.assertEqual(stats["dashboard"]["messages"], 3)
|
||||
self.assertEqual(stats["dashboard"]["initial_states"], 1)
|
||||
self.assertEqual(stats["dashboard"]["state_updates"], 1)
|
||||
self.assertEqual(stats["dashboard"]["state_messages"], 2)
|
||||
self.assertGreater(stats["dashboard"]["bytes"], stats["dashboard"]["state_bytes"])
|
||||
self.assertIn(bytes([0x8A]) + b"ping", FakePulse.pongs)
|
||||
self.assertFalse(agent_load.DASHBOARD_SOCKETS)
|
||||
|
||||
def test_warmup_dashboard_cannot_validate_steady_memory_comparison(self):
|
||||
since = int(time.time()) - 1
|
||||
|
||||
Reference in New Issue
Block a user