orchestra: complete 06G4V20T528ZTER7KZBVGNAYXC
This commit is contained in:
@@ -11,21 +11,33 @@ emit() {
|
|||||||
[ "$format" = none ] || printf "$@"
|
[ "$format" = none ] || printf "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# now_us: current time in microseconds. Strips any locale decimal separator.
|
||||||
|
now_us() { printf '%s' "${EPOCHREALTIME//[!0-9]/}"; }
|
||||||
|
|
||||||
|
# elapsed_ms <start-us>: whole milliseconds since <start-us>.
|
||||||
|
elapsed_ms() { printf '%s' "$(( ($(now_us) - $1) / 1000 ))"; }
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
local start_us
|
||||||
|
start_us=$(now_us)
|
||||||
local quiet=
|
local quiet=
|
||||||
local json=
|
local json=
|
||||||
|
local timing=
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [ "$arg" = --help ]; then
|
if [ "$arg" = --help ]; then
|
||||||
emit text 'Usage: %s [--quiet]\n\n' "${0##*/}"
|
emit text 'Usage: %s [--quiet] [--json] [--timing]\n\n' "${0##*/}"
|
||||||
emit text 'Healthcheck script for Orchestra E2E tests.\n'
|
emit text 'Healthcheck script for Orchestra E2E tests.\n'
|
||||||
emit text 'Exits 0 with a success message if all checks pass.\n'
|
emit text 'Exits 0 with a success message if all checks pass.\n'
|
||||||
emit text ' --quiet Suppress the success message; still exits 0.\n'
|
emit text ' --quiet Suppress the success message; still exits 0.\n'
|
||||||
|
emit text ' --timing Print elapsed milliseconds for each check.\n'
|
||||||
emit text 'Version: %s\n' "$VERSION"
|
emit text 'Version: %s\n' "$VERSION"
|
||||||
exit 0
|
exit 0
|
||||||
elif [ "$arg" = --quiet ]; then
|
elif [ "$arg" = --quiet ]; then
|
||||||
quiet=1
|
quiet=1
|
||||||
elif [ "$arg" = --json ]; then
|
elif [ "$arg" = --json ]; then
|
||||||
json=1
|
json=1
|
||||||
|
elif [ "$arg" = --timing ]; then
|
||||||
|
timing=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -33,11 +45,29 @@ main() {
|
|||||||
[ -n "$quiet" ] && format=none
|
[ -n "$quiet" ] && format=none
|
||||||
[ -n "$json" ] && format=json
|
[ -n "$json" ] && format=json
|
||||||
|
|
||||||
|
local -a TIMINGS=()
|
||||||
|
TIMINGS+=("healthchecks=$(elapsed_ms "$start_us")")
|
||||||
|
|
||||||
if [ "$format" = json ]; then
|
if [ "$format" = json ]; then
|
||||||
emit "$format" '{"status":"ok","checks":1}\n'
|
local timings=
|
||||||
|
if [ -n "$timing" ]; then
|
||||||
|
local sep=
|
||||||
|
for t in "${TIMINGS[@]}"; do
|
||||||
|
timings+="$sep\"${t%%=*}\":${t#*=}"
|
||||||
|
sep=,
|
||||||
|
done
|
||||||
|
timings=",\"timings\":{$timings}"
|
||||||
|
fi
|
||||||
|
emit "$format" '{"status":"ok","checks":%d%s}\n' "${#TIMINGS[@]}" "$timings"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$timing" ]; then
|
||||||
|
for t in "${TIMINGS[@]}"; do
|
||||||
|
emit "$format" '%s: %sms\n' "${t%%=*}" "${t#*=}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
emit "$format" 'OK - all healthchecks passed\n'
|
emit "$format" 'OK - all healthchecks passed\n'
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,16 @@
|
|||||||
|
|
||||||
HC="$(dirname "$0")/orchestra_e2e_healthcheck.sh"
|
HC="$(dirname "$0")/orchestra_e2e_healthcheck.sh"
|
||||||
OK='OK - all healthchecks passed'
|
OK='OK - all healthchecks passed'
|
||||||
USAGE="$(printf 'Usage: orchestra_e2e_healthcheck.sh [--quiet]\n\nHealthcheck script for Orchestra E2E tests.\nExits 0 with a success message if all checks pass.\n --quiet Suppress the success message; still exits 0.\nVersion: 1.0.0')"
|
USAGE="$(printf 'Usage: orchestra_e2e_healthcheck.sh [--quiet] [--json] [--timing]\n\nHealthcheck script for Orchestra E2E tests.\nExits 0 with a success message if all checks pass.\n --quiet Suppress the success message; still exits 0.\n --timing Print elapsed milliseconds for each check.\nVersion: 1.0.0')"
|
||||||
fails=0
|
fails=0
|
||||||
|
|
||||||
check() { # check <expected-stdout> <label> [args...]
|
check() { # check <expected-stdout> <label> [args...]
|
||||||
local want=$1 label=$2 got status
|
local want=$1 label=$2 got status raw
|
||||||
shift 2
|
shift 2
|
||||||
got=$(bash "$HC" "$@" 2>/dev/null)
|
raw=$(bash "$HC" "$@" 2>/dev/null)
|
||||||
status=$?
|
status=$?
|
||||||
|
# Durations vary per run, so normalise every digit run to N before comparing.
|
||||||
|
got=$(printf '%s' "$raw" | sed -E 's/[0-9]+ms/Nms/g; s/("healthchecks":)[0-9]+/\1N/g')
|
||||||
if [ "$got" != "$want" ] || [ "$status" -ne 0 ]; then
|
if [ "$got" != "$want" ] || [ "$status" -ne 0 ]; then
|
||||||
printf 'FAIL: %s (exit=%s)\n---got---\n%s\n---want---\n%s\n' "$label" "$status" "$got" "$want"
|
printf 'FAIL: %s (exit=%s)\n---got---\n%s\n---want---\n%s\n' "$label" "$status" "$got" "$want"
|
||||||
fails=$((fails + 1))
|
fails=$((fails + 1))
|
||||||
@@ -23,6 +25,9 @@ check "$USAGE" '--help' --help
|
|||||||
check "$USAGE" '--help --quiet' --help --quiet
|
check "$USAGE" '--help --quiet' --help --quiet
|
||||||
check "$USAGE" '--quiet --help' --quiet --help
|
check "$USAGE" '--quiet --help' --quiet --help
|
||||||
check "$OK" 'unknown flag ignored' --bogus
|
check "$OK" 'unknown flag ignored' --bogus
|
||||||
|
check "$(printf 'healthchecks: Nms\n%s' "$OK")" '--timing' --timing
|
||||||
|
check '' '--timing --quiet' --timing --quiet
|
||||||
|
check '{"status":"ok","checks":1,"timings":{"healthchecks":N}}' '--timing --json' --timing --json
|
||||||
|
|
||||||
[ "$fails" -eq 0 ] || exit 1
|
[ "$fails" -eq 0 ] || exit 1
|
||||||
printf 'all checks passed\n'
|
printf 'all checks passed\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user