Add data_collection/tests/test_core.py

This commit is contained in:
Mika 2026-03-30 16:33:36 +00:00
parent 6bff3c3f00
commit 79e0bfaf56

View file

@ -0,0 +1,45 @@
import pytest
import time
from datetime import datetime, timezone
from data_collection import core
def test_collect_run_data_structure_and_types():
result = core.collect_run_data(run_id=1, worker_count=2)
assert isinstance(result, dict), "Return type muss dict sein"
expected_fields = {"epoch_ms": int, "monotonic_ns": int, "tz_offset_minutes": int, "retry_tail_p99": float, "band_width": float}
for field, ftype in expected_fields.items():
assert field in result, f"Feld {field} fehlt im Ergebnis"
assert isinstance(result[field], ftype), f"Feld {field} muss Typ {ftype.__name__} haben"
def test_epoch_ms_reasonable_range():
result = core.collect_run_data(run_id=5, worker_count=1)
now_ms = int(time.time() * 1000)
assert abs(result["epoch_ms"] - now_ms) < 1000 * 5, "epoch_ms sollte aktueller Zeit entsprechen"
def test_monotonic_ns_increasing():
first = core.collect_run_data(run_id=2, worker_count=3)
time.sleep(0.001)
second = core.collect_run_data(run_id=2, worker_count=3)
assert second["monotonic_ns"] > first["monotonic_ns"], "monotonic_ns sollte mit der Zeit steigen"
def test_tz_offset_nonzero_or_known():
result = core.collect_run_data(run_id=3, worker_count=4)
assert isinstance(result["tz_offset_minutes"], int)
assert -720 <= result["tz_offset_minutes"] <= 840, "tz_offset_minutes sollte gültiger Offset sein"
def test_retry_tail_p99_and_bandwidth_values():
result = core.collect_run_data(run_id=10, worker_count=5)
assert result["retry_tail_p99"] >= 0.0, "retry_tail_p99 sollte positiv sein"
assert result["band_width"] > 0.0, "band_width sollte > 0 sein"
def test_multiple_invocations_yield_distinct_results():
r1 = core.collect_run_data(run_id=11, worker_count=1)
r2 = core.collect_run_data(run_id=11, worker_count=1)
assert r1 != r2, "Zwei Messungen sollten sich unterscheiden (Zeit)"