-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-e2e-tests-local-fast.sh
More file actions
executable file
·184 lines (165 loc) · 6.72 KB
/
Copy pathrun-e2e-tests-local-fast.sh
File metadata and controls
executable file
·184 lines (165 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# Fast Local E2E Test Runner — Artemis Benchmarking
# =============================================================================
# Runs the server (./gradlew bootRun) and client (pnpm start) directly on the
# host, with PostgreSQL in a small throwaway container. No production image build,
# so it is much faster than ./run-e2e-tests-local.sh. Services are left running
# between runs, so re-runs (with --skip-*) take only seconds.
#
# If you already have a PostgreSQL on localhost:5432 (db "benchmarking",
# user/password "benchmarking" — matching the dev profile), use --skip-db to run
# with no Docker at all.
#
# Usage:
# ./run-e2e-tests-local-fast.sh [options] [-- <extra playwright args>]
#
# Options:
# --stop Kill the server, client and PostgreSQL container; then exit
# --skip-db Reuse an already-running PostgreSQL on localhost:5432
# --skip-server Reuse an already-running server on :8080
# --skip-client Reuse an already-running client on :9000
# --ui Open the Playwright UI
# --headed Run the browser headed
# --help Show this help message
# =============================================================================
cd "$(dirname "$0")"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log() { echo -e "${BLUE}[e2e]${NC} $*"; }
ok() { echo -e "${GREEN}[e2e]${NC} $*"; }
warn() { echo -e "${YELLOW}[e2e]${NC} $*"; }
err() { echo -e "${RED}[e2e]${NC} $*"; }
LOCAL_DIR=".e2e-local"
POSTGRES_CONTAINER="benchmarking-e2e-postgres"
SERVER_PORT=8080
CLIENT_PORT=9000
export E2E_BASE_URL="http://localhost:${CLIENT_PORT}"
STOP=false
SKIP_DB=false
SKIP_SERVER=false
SKIP_CLIENT=false
PLAYWRIGHT_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--stop) STOP=true; shift ;;
--skip-db) SKIP_DB=true; shift ;;
--skip-server) SKIP_SERVER=true; shift ;;
--skip-client) SKIP_CLIENT=true; shift ;;
--ui) PLAYWRIGHT_ARGS+=(--ui); shift ;;
--headed) PLAYWRIGHT_ARGS+=(--headed); shift ;;
--help) head -33 "$0" | tail -28; exit 0 ;;
--) shift; PLAYWRIGHT_ARGS+=("$@"); break ;;
*) PLAYWRIGHT_ARGS+=("$1"); shift ;;
esac
done
# Recursively kill a process and its children (portable: macOS + Linux).
kill_tree() {
local pid=$1
for child in $(pgrep -P "$pid" 2>/dev/null); do kill_tree "$child"; done
kill "$pid" 2>/dev/null || true
}
# Kill a previously started background process tracked via a PID file.
kill_pidfile() {
local name=$1 file="$LOCAL_DIR/$1.pid"
if [ -f "$file" ]; then
local pid; pid=$(cat "$file")
if kill -0 "$pid" 2>/dev/null; then log "Stopping $name (PID $pid)..."; kill_tree "$pid"; fi
rm -f "$file"
fi
}
# Free a TCP port by killing whatever listens on it (stale process from a
# previous run). Hands-free re-runs should not require manual cleanup.
free_port() {
local port=$1 label=$2 pids
pids=$(lsof -nP -iTCP:"$port" -sTCP:LISTEN -t 2>/dev/null || true)
if [ -n "$pids" ]; then
warn "Port $port ($label) in use — killing $(echo "$pids" | tr '\n' ' ')..."
for pid in $pids; do kill_tree "$pid"; done
sleep 2
fi
}
wait_for_url() {
local url=$1 label=$2 timeout=${3:-300} elapsed=0
log "Waiting for $label ..."
until curl -sf "$url" >/dev/null 2>&1; do
if [ "$elapsed" -ge "$timeout" ]; then err "$label not ready after ${timeout}s"; return 1; fi
sleep 3; elapsed=$((elapsed + 3))
done
ok "$label ready (${elapsed}s)"
}
if [ "$STOP" = true ]; then
log "Stopping all fast e2e services..."
kill_pidfile "client"; free_port "$CLIENT_PORT" "client"
kill_pidfile "server"; free_port "$SERVER_PORT" "server"
docker rm -f "$POSTGRES_CONTAINER" >/dev/null 2>&1 || true
rm -rf "$LOCAL_DIR"
ok "All services stopped."
exit 0
fi
command -v corepack >/dev/null 2>&1 && corepack enable >/dev/null 2>&1 || true
for cmd in docker java node pnpm curl; do
command -v "$cmd" >/dev/null 2>&1 || { err "Missing required command: $cmd"; exit 1; }
done
mkdir -p "$LOCAL_DIR"
# --- PostgreSQL (port 5432, matching the dev profile) ------------------------
if [ "$SKIP_DB" = true ]; then
warn "Skipping PostgreSQL (--skip-db) — expecting one on localhost:5432."
elif lsof -nP -iTCP:5432 -sTCP:LISTEN >/dev/null 2>&1; then
log "PostgreSQL already listening on localhost:5432 — using the existing instance."
else
log "Starting PostgreSQL container ($POSTGRES_CONTAINER) on localhost:5432..."
docker rm -f "$POSTGRES_CONTAINER" >/dev/null 2>&1 || true
docker run -d --name "$POSTGRES_CONTAINER" -p 127.0.0.1:5432:5432 \
-e POSTGRES_DB=benchmarking -e POSTGRES_USER=benchmarking -e POSTGRES_PASSWORD=benchmarking \
postgres:18-alpine >/dev/null
elapsed=0
until docker exec "$POSTGRES_CONTAINER" pg_isready -U benchmarking -d benchmarking >/dev/null 2>&1; do
if [ "$elapsed" -ge 120 ]; then err "PostgreSQL not ready after 120s"; exit 1; fi
sleep 3; elapsed=$((elapsed + 3))
done
ok "PostgreSQL ready (${elapsed}s)"
fi
# --- Server (Spring Boot, dev profile -> PostgreSQL on 5432) -----------------
if [ "$SKIP_SERVER" = false ]; then
kill_pidfile "server"; free_port "$SERVER_PORT" "server"
log "Starting server (./gradlew bootRun); log: $LOCAL_DIR/server.log"
./gradlew bootRun >"$LOCAL_DIR/server.log" 2>&1 &
echo $! >"$LOCAL_DIR/server.pid"
else
warn "Skipping server (--skip-server)."
fi
# --- Client (Angular dev server on :9000, proxies to the server) -------------
if [ "$SKIP_CLIENT" = false ]; then
kill_pidfile "client"; free_port "$CLIENT_PORT" "client"
log "Starting client (pnpm start); log: $LOCAL_DIR/client.log"
pnpm start >"$LOCAL_DIR/client.log" 2>&1 &
echo $! >"$LOCAL_DIR/client.pid"
else
warn "Skipping client (--skip-client)."
fi
[ "$SKIP_SERVER" = false ] && wait_for_url "http://localhost:${SERVER_PORT}/management/health" "server" 300
[ "$SKIP_CLIENT" = false ] && wait_for_url "$E2E_BASE_URL" "client" 180
# --- Playwright --------------------------------------------------------------
log "Installing the Playwright browser..."
pnpm exec playwright install chromium >/dev/null
echo ""
log "Running Playwright e2e tests against $E2E_BASE_URL ..."
echo ""
EXIT_CODE=0
pnpm exec playwright test "${PLAYWRIGHT_ARGS[@]+"${PLAYWRIGHT_ARGS[@]}"}" || EXIT_CODE=$?
echo ""
if [ "$EXIT_CODE" -eq 0 ]; then
ok "All e2e tests passed."
else
err "Some e2e tests failed (exit code $EXIT_CODE)."
warn "View the report: pnpm exec playwright show-report"
fi
echo ""
warn "Services are still running. Quick re-run:"
echo " ./run-e2e-tests-local-fast.sh --skip-db --skip-server --skip-client"
warn "To stop everything:"
echo " ./run-e2e-tests-local-fast.sh --stop"
echo ""
log "Logs: $LOCAL_DIR/server.log, $LOCAL_DIR/client.log"
exit "$EXIT_CODE"