forked from boos/BoosAPI
chore: sync current workspace changes
This commit is contained in:
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
SOURCE_RUNTIME_DIR="${PGRUST_RUNTIME_DIR:-$ROOT_DIR/dist/pgrust}"
|
||||
APP_PORT="${BOOSAPI_SMOKE_PORT:-4402}"
|
||||
SMOKE_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/boosapi-pgrust-smoke.XXXXXX")"
|
||||
DATA_DIR="$SMOKE_ROOT/data"
|
||||
RUNTIME_DIR="$SMOKE_ROOT/runtime"
|
||||
CONFIG_PATH="$SMOKE_ROOT/config.toml"
|
||||
APP_LOG="$SMOKE_ROOT/boosapi.log"
|
||||
APP_PID=""
|
||||
|
||||
cleanup() {
|
||||
local status=$?
|
||||
if [ -n "$APP_PID" ] && kill -0 "$APP_PID" 2>/dev/null; then
|
||||
kill -INT "$APP_PID" 2>/dev/null || true
|
||||
wait "$APP_PID" 2>/dev/null || true
|
||||
fi
|
||||
if pgrep -f -- "-D $DATA_DIR" >/dev/null 2>&1; then
|
||||
pkill -INT -f -- "-D $DATA_DIR" 2>/dev/null || true
|
||||
fi
|
||||
if [ "$status" -ne 0 ] && [ -s "$APP_LOG" ]; then
|
||||
cat "$APP_LOG" >&2
|
||||
fi
|
||||
rm -rf "$SMOKE_ROOT"
|
||||
return "$status"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
for command in cargo curl jq pgrep; do
|
||||
command -v "$command" >/dev/null || {
|
||||
echo "missing required command: $command" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
if [ ! -x "$SOURCE_RUNTIME_DIR/bin/postgres" ]; then
|
||||
scripts/build_pgrust_runtime.sh
|
||||
fi
|
||||
chmod 755 "$SMOKE_ROOT"
|
||||
cp -a "$SOURCE_RUNTIME_DIR" "$RUNTIME_DIR"
|
||||
chmod -R a+rX "$RUNTIME_DIR"
|
||||
cp config.toml "$CONFIG_PATH"
|
||||
|
||||
cargo rustc --bin boosapi -- -C linker=clang -C link-arg=-fuse-ld=mold
|
||||
|
||||
common_env=(
|
||||
"BOOSAPI_PGRUST__RUNTIME_DIR=$RUNTIME_DIR"
|
||||
"BOOSAPI_PGRUST__DATA_DIR=$DATA_DIR"
|
||||
"BOOSAPI_REDIS__ENABLED=false"
|
||||
)
|
||||
|
||||
env "${common_env[@]}" target/debug/boosapi --config "$CONFIG_PATH" --migrate-only
|
||||
test -f "$DATA_DIR/PG_VERSION"
|
||||
test ! -f "$DATA_DIR/postmaster.pid"
|
||||
|
||||
env "${common_env[@]}" \
|
||||
BOOSAPI_SERVER__PORT="$APP_PORT" \
|
||||
BOOSAPI_AUTH__AUTH_TOKEN=pgrust-smoke-admin-token \
|
||||
target/debug/boosapi --config "$CONFIG_PATH" >"$APP_LOG" 2>&1 &
|
||||
APP_PID=$!
|
||||
|
||||
for _ in $(seq 1 120); do
|
||||
if curl --fail --silent "http://127.0.0.1:${APP_PORT}/healthz" \
|
||||
| jq -e '.status == "ok" and .database == "ok"' >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if ! kill -0 "$APP_PID" 2>/dev/null; then
|
||||
wait "$APP_PID" || true
|
||||
exit 1
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
|
||||
curl --fail --silent \
|
||||
-H 'Authorization: Bearer pgrust-smoke-admin-token' \
|
||||
"http://127.0.0.1:${APP_PORT}/api/admin/users" \
|
||||
| jq -e '(.users | type) == "array"' >/dev/null
|
||||
|
||||
pgrep -f -- "-D $DATA_DIR" >/dev/null
|
||||
kill -INT "$APP_PID"
|
||||
wait "$APP_PID"
|
||||
APP_PID=""
|
||||
|
||||
for _ in $(seq 1 40); do
|
||||
if ! pgrep -f -- "-D $DATA_DIR" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 0.25
|
||||
done
|
||||
if pgrep -f -- "-D $DATA_DIR" >/dev/null 2>&1; then
|
||||
echo "embedded pgrust process did not stop with BoosAPI" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "embedded pgrust smoke test passed"
|
||||
Reference in New Issue
Block a user