Add API integration checks, migration compatibility, rolling restart scenarios and a report verification collector.
36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
import tempfile
|
|
|
|
spec = importlib.util.spec_from_file_location("diagnostics", Path(__file__).resolve().parents[1] / "scripts/run-scaling-diagnostics.py")
|
|
diagnostics = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(diagnostics)
|
|
|
|
|
|
class SummaryTest(unittest.TestCase):
|
|
def test_cumulative_counters_become_interval_rates(self):
|
|
summary = diagnostics.resource_summary([
|
|
{"time_ms": 1000, "cpu_usage_usec": 100, "cpu_nr_periods": 10,
|
|
"cpu_nr_throttled": 1, "cpu_throttled_usec": 100, "memory_bytes": 1024**2},
|
|
{"time_ms": 3000, "cpu_usage_usec": 1000100, "cpu_nr_periods": 30,
|
|
"cpu_nr_throttled": 6, "cpu_throttled_usec": 500100, "memory_bytes": 2*1024**2},
|
|
])
|
|
self.assertEqual(summary["mean_cpu_cores"], 0.5)
|
|
self.assertEqual(summary["throttled_period_fraction"], 0.25)
|
|
self.assertEqual(summary["throttled_seconds"], 0.5)
|
|
self.assertEqual(summary["peak_memory_mib"], 2)
|
|
|
|
def test_short_sample_does_not_invent_rates(self):
|
|
self.assertEqual(diagnostics.resource_summary([]), {"samples": 0})
|
|
|
|
def test_postgres_multiline_json_and_incomplete_tail(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = Path(directory) / "postgres.jsonl"
|
|
path.write_text('{"kind":"postgres",\n"activity":[\n{"state":"active"}\n]}\n{"kind":"cgroup"}\n{"unfinished":', encoding="utf-8")
|
|
self.assertEqual([r["kind"] for r in diagnostics.rows(path)], ["postgres", "cgroup"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|