my-homelab-configs/tests/jeannie/test_report_parallel.py

39 lines
1.5 KiB
Python

"""Read-only report orchestration regression; run on the Debian host."""
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
class ParallelReportTests(unittest.TestCase):
def test_order_cache_and_failure_are_preserved(self):
with tempfile.TemporaryDirectory() as directory:
env = dict(os.environ, PROBE_COUNTER=str(Path(directory) / "calls"), LAB_REPORT_PARALLELISM="2")
program = r'''
set -euo pipefail
source scripts/report-ui
status_http_ok() { printf 'call\n' >>"$PROBE_COUNTER"; return 0; }
failed_probe() { echo 'unreachable'; return 1; }
report_ui_begin
REPORT_UI_PARALLEL=true
report_ui_check fail A first fix '' '' status_http_ok same
report_ui_check fail A second fix '' '' status_http_ok same
report_ui_check fail A third fix '' '' failed_probe
report_ui_finish
cat "$REPORT_UI_ROWS_FILE"
printf 'failures=%s\n' "$REPORT_UI_FAILURES"
report_ui_cleanup
'''
result = subprocess.run(["bash", "-c", program], cwd=ROOT, env=env,
text=True, capture_output=True, check=True)
lines = result.stdout.splitlines()
self.assertEqual([line.split("\t")[2] for line in lines[:3]], ["first", "second", "third"])
self.assertEqual([line.split("\t")[0] for line in lines[:3]], ["ok", "ok", "fail"])
self.assertIn("failures=1", lines)
self.assertEqual(Path(env["PROBE_COUNTER"]).read_text().splitlines(), ["call"])