droboticflow/scripts/test_dashboard_stability.py

64 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""Release gate: synthetic local Mongo + real loader/API/recovery regressions.
The fixed loopback URI is intentional. Never accepts a production database URI.
"""
import json
import os
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[1]
REQUIRED = {
"TestAnnotationOutputLargeRelatedSetsRemainBoundedAndComplete",
"TestAnnotationOutputNonReportingHistoryDoesNotConsumeBudget",
"TestAnnotationOutputRunLinkIndexIsDeclared",
"TestAnnotationOutputMongoFailureDiagnosticsSurviveRestart",
"TestAnnotationOutputMongoSharedAcrossInstancesAndRestart",
"TestAnnotationOutputHealthIsAdminScopedAndReadOnly",
"TestFailureDiagnosticsSurviveLeaseTakeoverAndClearAfterSuccess",
"TestHealthWarnsBeforeExpiryAndDoesNotTriggerBuild",
"TestAnnotationOutputDatasetPreservesRulesAcrossFilters",
"TestRouteSnapshot",
}
def verify_events(events, returncode):
passed = {e.get("Test") for e in events if e.get("Action") == "pass"}
skipped = {e.get("Test") for e in events if e.get("Action") == "skip"}
missing = sorted(REQUIRED - passed)
return {"passed": returncode == 0 and not missing and not skipped,
"missingOrFailed": missing, "skipped": sorted(x for x in skipped if x)}
def main():
env = dict(os.environ, TEST_WORKFORCE_MONGO_URI="mongodb://127.0.0.1:27018", RUN_OUTPUT_HISTORY_SCALE="1", RUN_OUTPUT_SNAPSHOT_BENCHMARK="1")
command = ["go", "test", "-json", "-race", "./internal/outputsnapshot", "./internal/store",
"./internal/workforcestats", "./internal/api", "-run",
"TestAnnotationOutput|TestOutput|TestSharedReaders|TestRefreshFailure|TestLeaseRecovery|"
"TestCorruptCurrent|TestBuildCancellation|TestSnapshotScope|TestFailedBuild|"
"TestFailureDiagnostics|TestHealth|TestRouteSnapshot", "-count=1", "-timeout=120s"]
try:
result = subprocess.run(command, cwd=ROOT, env=env, capture_output=True, text=True, timeout=240)
except (OSError, subprocess.TimeoutExpired):
print(json.dumps({"passed": False, "error": "stability_runner_failed"}))
return 1
events = []
for line in result.stdout.splitlines():
try:
event = json.loads(line)
except ValueError:
continue
events.append(event)
if event.get("Action") == "output":
sys.stdout.write(event.get("Output", ""))
if result.stderr:
sys.stderr.write(result.stderr)
verdict = verify_events(events, result.returncode)
print(json.dumps(verdict))
return 0 if verdict["passed"] else 1
if __name__ == "__main__":
raise SystemExit(main())