GuestOps/tests/test_capacity_probe.py
wolf-demon 2e8cf269fb
Some checks are pending
Build and verify web migration / verify (push) Waiting to run
miledtone 17
2026-09-29 20:44:39 +01:00

27 lines
979 B
Python

import importlib.util
from pathlib import Path
import unittest
spec = importlib.util.spec_from_file_location("capacity_probe", Path(__file__).resolve().parents[1] / "deploy" / "capacity_probe.py")
probe = importlib.util.module_from_spec(spec)
spec.loader.exec_module(probe)
class CapacityProbeTests(unittest.TestCase):
def test_summary_reports_failures_and_nearest_rank_latency(self):
report = probe.summarize([(True, 10), (True, 20), (False, 30), (True, 40), (True, 100)], 2)
self.assertEqual(report["requests"], 5)
self.assertEqual(report["successes"], 4)
self.assertEqual(report["failures"], 1)
self.assertEqual(report["errorRate"], 0.2)
self.assertEqual(report["latencyMs"], {"median": 30, "p95": 100, "maximum": 100})
def test_summary_rejects_empty_results(self):
with self.assertRaisesRegex(ValueError, "At least one"):
probe.summarize([], 1)
if __name__ == "__main__":
unittest.main()