cc11082ea7
CI / lint-test-build (push) Failing after 19s
- Added synthetic latency profiler scenarios and CLI scripts for baseline generation and regression checks. - Introduced latency baseline and threshold artifacts for CI enforcement. - Enhanced CI workflow with latency guardrail checks. - Updated documentation to include latency profiling commands and performance metrics. - Added unit tests for latency guardrail evaluation.
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from arbitrade.perf.guardrails import evaluate_guardrails
|
|
from arbitrade.perf.latency import run_latency_profile
|
|
|
|
|
|
def test_run_latency_profile_contains_expected_shape() -> None:
|
|
profile = run_latency_profile(iterations=50)
|
|
|
|
scenarios = profile.get("scenarios")
|
|
assert isinstance(scenarios, dict)
|
|
assert set(scenarios) == {
|
|
"book_update_burst",
|
|
"execution_spike",
|
|
"reconnect_storm",
|
|
}
|
|
|
|
for payload in scenarios.values():
|
|
assert isinstance(payload, dict)
|
|
stages = payload.get("stages")
|
|
assert isinstance(stages, dict)
|
|
assert "end_to_end" in stages
|
|
|
|
|
|
def test_evaluate_guardrails_flags_regression() -> None:
|
|
baseline = {
|
|
"scenarios": {
|
|
"book_update_burst": {
|
|
"stages": {
|
|
"end_to_end": {"p95_ms": 1.0, "p99_ms": 1.0},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
current = {
|
|
"scenarios": {
|
|
"book_update_burst": {
|
|
"stages": {
|
|
"end_to_end": {"p95_ms": 4.0, "p99_ms": 4.0},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
thresholds = {"default": {"p95_ms": 2.0, "p99_ms": 2.0}}
|
|
|
|
failures = evaluate_guardrails(baseline=baseline, current=current, thresholds=thresholds)
|
|
|
|
assert failures
|
|
assert "latency regression" in failures[0]
|