uce/tests/plugins/uce_demo_smoke.py

45 lines
1.5 KiB
Python

from pathlib import Path
from run_network_tests import TestFailure
# The demo pages are not regression suites, but every one of them must at
# least compile and render: a preprocessor or runtime change that breaks a
# demo page (e.g. literal text that looks like an entry point) should fail CI.
ERROR_MARKERS = [
"uce compile error",
"fatal signal during request",
"uncaught exception during request",
]
def _repo_root():
return Path(__file__).resolve().parents[2]
def _make_demo_case(page_path):
def run(context):
# sharedunit.uce exercises compiler_load_shared_unit() and can cold-compile
# through the native fallback in a fresh worker process; keep the smoke gate
# strict on status/body while allowing that one cold path enough time.
response = context.request(page_path, timeout=15.0 if page_path.endswith("/sharedunit.uce") else None)
if response.status != 200:
raise TestFailure("expected HTTP 200 for %s, got %s %s" % (page_path, response.status, response.reason))
body_lower = response.text.lower()
for marker in ERROR_MARKERS:
if marker in body_lower:
raise Exception("response body contained error marker %r for %s" % (marker, page_path))
return "HTTP 200 without error markers for %s" % page_path
return run
def register(registry):
demo_dir = _repo_root() / "site" / "demo"
for path in sorted(demo_dir.glob("*.uce")):
registry.case(
"demo page " + path.name,
_make_demo_case("/demo/" + path.name),
tags=["http", "smoke", "uce", "demo", "public"],
)