-
Notifications
You must be signed in to change notification settings - Fork 1
ci: harden smoke tests to catch Windows dev-mode SSR and perf regressions #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rsbh
wants to merge
6
commits into
main
Choose a base branch
from
ci/windows-dev-smoke-hardening
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−34
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca82d3e
ci: harden smoke tests with log capture, fail-fast, and process-tree …
rsbh 6d79b01
ci: exercise the default Windows dev runner in smoke tests
rsbh 0233891
ci: crawl sitemap pages and detect SSR errors in smoke tests
rsbh c60a017
ci: enforce first-load and warm-load time budgets in smoke tests
rsbh 80d03b7
ci: fix SIGPIPE failure when truncating sitemap crawl list
rsbh f825ff7
ci: address review feedback on smoke test script
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #!/usr/bin/env bash | ||
| # Smoke test a chronicle server against examples/basic. | ||
| # Usage: scripts/smoke-test.sh <dev|start> <port> | ||
| set -euo pipefail | ||
|
|
||
| MODE="${1:?usage: smoke-test.sh <dev|start> <port>}" | ||
| PORT="${2:?usage: smoke-test.sh <dev|start> <port>}" | ||
| BASE="http://localhost:${PORT}" | ||
| LOG_FILE="smoke-${MODE}.log" | ||
|
|
||
| ./packages/chronicle/bin/chronicle.js "$MODE" --config examples/basic/chronicle.yaml --port "$PORT" >"$LOG_FILE" 2>&1 & | ||
| SERVER_PID=$! | ||
|
|
||
| cleanup() { | ||
| # Git Bash `kill` doesn't reach grandchild node processes on Windows | ||
| if [[ "${RUNNER_OS:-}" == "Windows" ]]; then | ||
| taskkill //F //T //PID "$SERVER_PID" >/dev/null 2>&1 || true | ||
| else | ||
| kill "$SERVER_PID" 2>/dev/null || true | ||
| fi | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| fail() { | ||
| echo "FAIL: $1" | ||
| echo "--- server log (${LOG_FILE}) ---" | ||
| cat "$LOG_FILE" | ||
| exit 1 | ||
| } | ||
|
|
||
| # Wall-clock deadline; SECONDS counts from script start, which includes server spawn | ||
| HEALTH_BUDGET="${HEALTH_BUDGET:-120}" | ||
| healthy=0 | ||
| while (( SECONDS < HEALTH_BUDGET )); do | ||
| if ! kill -0 "$SERVER_PID" 2>/dev/null; then | ||
| fail "${MODE} server exited before becoming healthy" | ||
| fi | ||
| if curl -sf --max-time 5 "${BASE}/api/health" | grep -q '"ok"'; then | ||
| healthy=1 | ||
| break | ||
| fi | ||
| sleep 2 | ||
| done | ||
| if [[ "$healthy" -ne 1 ]]; then | ||
| fail "${MODE} server not healthy after ${HEALTH_BUDGET}s" | ||
| fi | ||
| echo "${MODE} server health check passed" | ||
|
|
||
| # Load-time budgets (seconds); first load includes SSR compile in dev mode | ||
| FIRST_LOAD_BUDGET="${FIRST_LOAD_BUDGET:-60}" | ||
| WARM_LOAD_BUDGET="${WARM_LOAD_BUDGET:-10}" | ||
| BODY_FILE="smoke-${MODE}-page.html" | ||
|
|
||
| first_time=$(curl -sfL -o "$BODY_FILE" -w '%{time_total}' --max-time "$FIRST_LOAD_BUDGET" "${BASE}/") \ | ||
| || fail "first page load failed or exceeded ${FIRST_LOAD_BUDGET}s budget" | ||
| if ! grep -q 'getting-started' "$BODY_FILE"; then | ||
| fail "homepage does not contain expected content" | ||
| fi | ||
| echo "${MODE} server content check passed (first load ${first_time}s, budget ${FIRST_LOAD_BUDGET}s)" | ||
|
|
||
| warm_time=$(curl -sfL -o /dev/null -w '%{time_total}' --max-time "$WARM_LOAD_BUDGET" "${BASE}/") \ | ||
| || fail "warm page load failed or exceeded ${WARM_LOAD_BUDGET}s budget" | ||
| echo "${MODE} server warm load check passed (${warm_time}s, budget ${WARM_LOAD_BUDGET}s)" | ||
|
|
||
| if ! curl -sf --max-time 30 "${BASE}/api/page?slug=docs,getting-started" | grep -q '"title"'; then | ||
| fail "page API did not return page metadata" | ||
| fi | ||
| echo "${MODE} server page API check passed" | ||
|
|
||
| # Crawl pages from the sitemap; in dev mode each request exercises SSR compile | ||
| CRAWL_LIMIT="${CRAWL_LIMIT:-15}" | ||
| CRAWL_BUDGET="${CRAWL_BUDGET:-300}" | ||
|
|
||
| # `|| true`: an empty sitemap makes grep exit 1, which must reach the | ||
| # explicit fail below instead of killing the script under pipefail | ||
| paths=$(curl -sf --max-time 30 "${BASE}/sitemap.xml" \ | ||
| | grep -o '<loc>[^<]*</loc>' \ | ||
| | sed -E -e 's|</?loc>||g' -e 's|^https?://[^/]*||' -e 's|^$|/|' \ | ||
| | awk -v n="$CRAWL_LIMIT" 'NR <= n' || true) | ||
| if [[ -z "$paths" ]]; then | ||
| fail "sitemap.xml returned no URLs" | ||
| fi | ||
|
|
||
| crawled=0 | ||
| crawl_start=$SECONDS | ||
| while IFS= read -r page_path; do | ||
| if (( SECONDS - crawl_start > CRAWL_BUDGET )); then | ||
| fail "crawl exceeded ${CRAWL_BUDGET}s budget after ${crawled} pages" | ||
| fi | ||
| status=$(curl -sL -o "$BODY_FILE" -w '%{http_code}' --max-time 30 "${BASE}${page_path}") || status=000 | ||
| if [[ "$status" != "200" ]]; then | ||
| fail "GET ${page_path} returned HTTP ${status}" | ||
| fi | ||
| if ! grep -q '</html>' "$BODY_FILE"; then | ||
| fail "GET ${page_path} returned truncated or incomplete HTML" | ||
| fi | ||
| crawled=$((crawled + 1)) | ||
| done <<<"$paths" | ||
| echo "${MODE} server crawl passed (${crawled} pages)" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.