feat(reporter): add uptime and fleet counters to state snapshot
This commit is contained in:
1 parent
7f323ed78b
commit
3b1e25d5cd
6 files changed
+55
-6
No files matched your search
+3
-3
@@ -101,7 +101,7 @@ class PostHealVerificationTests(unittest.TestCase):
|
||||
self.assertEqual(1, len(reporter.update_calls))
|
||||
self.assertTrue(reporter.update_calls[0]["is_synced"])
|
||||
self.assertEqual(12, reporter.update_calls[0]["ban_count"])
|
||||
self.assertEqual("success", reporter.update_calls[0]["last_heal_result"])
|
||||
self.assertEqual("success", reporter.update_calls[0]["heal_result"])
|
||||
self.assertEqual("", reporter.update_calls[0]["last_drift_fingerprint"])
|
||||
self.assertEqual({"fingerprint": "pre123"}, auditor.last_heal_drift)
|
||||
|
||||
@@ -124,7 +124,7 @@ class PostHealVerificationTests(unittest.TestCase):
|
||||
self.assertFalse(reporter.update_calls[0]["is_synced"])
|
||||
self.assertEqual(7, reporter.update_calls[0]["ban_count"])
|
||||
self.assertEqual("Bouncer restart failed", reporter.update_calls[0]["last_error"])
|
||||
self.assertEqual("restart_failed", reporter.update_calls[0]["last_heal_result"])
|
||||
self.assertEqual("restart_failed", reporter.update_calls[0]["heal_result"])
|
||||
|
||||
@patch("healing.time.sleep", return_value=None)
|
||||
def test_execute_heal_and_verify_verify_exception(self, _sleep):
|
||||
@@ -145,7 +145,7 @@ class PostHealVerificationTests(unittest.TestCase):
|
||||
self.assertFalse(reporter.update_calls[0]["is_synced"])
|
||||
self.assertEqual(7, reporter.update_calls[0]["ban_count"])
|
||||
self.assertIn("Post-heal verify error: boom", reporter.update_calls[0]["last_error"])
|
||||
self.assertEqual("verify_error", reporter.update_calls[0]["last_heal_result"])
|
||||
self.assertEqual("verify_error", reporter.update_calls[0]["heal_result"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -61,6 +61,25 @@ class ReporterStateTests(unittest.TestCase):
|
||||
self.assertEqual("success", payload["last_heal_result"])
|
||||
self.assertEqual("", payload["last_drift_fingerprint"])
|
||||
|
||||
def test_update_status_tracks_checks_and_heal_counters(self):
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
state_file = os.path.join(tmp_dir, "state.json")
|
||||
reporter = LocalStateReporter(state_file=state_file, node_name="n1")
|
||||
|
||||
reporter.update_status(True, 1, checks_increment=1)
|
||||
reporter.update_status(True, 1, checks_increment=1)
|
||||
reporter.update_status(False, 1, heal_result="failed")
|
||||
reporter.update_status(True, 1, heal_result="success")
|
||||
|
||||
with open(state_file, "r") as f:
|
||||
payload = json.load(f)
|
||||
|
||||
self.assertEqual(2, payload["checks_total"])
|
||||
self.assertEqual(2, payload["heals_total"])
|
||||
self.assertEqual(1, payload["heal_failures_total"])
|
||||
self.assertEqual("success", payload["last_heal_result"])
|
||||
self.assertGreaterEqual(payload["uptime_seconds"], 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user