Refactor Jenkinsfile and wait-for-jenkins-stack.sh for improved E2E testing
- Removed the wait-for-jenkins-stack.sh script from the Jenkinsfile, integrating its functionality directly into the Jenkins pipeline for better clarity and efficiency. - Enhanced the wait logic for backend and frontend services, implementing a reusable function in the script to streamline the waiting process and improve error handling. - Updated comments to clarify the purpose and behavior of the changes, ensuring better understanding of the E2E testing setup.
This commit is contained in:
@@ -1,31 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Espera API y Vite levantados en el host (tras docker compose), para E2E en CI.
|
||||
# Espera a que backend y frontend estén sirviendo tras `docker compose up`.
|
||||
#
|
||||
# Uso en Jenkins: el wait real corre dentro del contenedor Playwright con
|
||||
# --network host (ver Jenkinsfile). Este script es para dev/local cuando los
|
||||
# puertos 8000/5173 sí son alcanzables desde el shell que lo invoca.
|
||||
set -euo pipefail
|
||||
BACKEND_MAX_SEC="${BACKEND_MAX_SEC:-600}"
|
||||
|
||||
BACKEND_URL="${BACKEND_URL:-http://localhost:8000/api/health}"
|
||||
FRONTEND_URL="${FRONTEND_URL:-http://localhost:5173/}"
|
||||
BACKEND_MAX_SEC="${BACKEND_MAX_SEC:-900}"
|
||||
FRONTEND_MAX_SEC="${FRONTEND_MAX_SEC:-300}"
|
||||
i=0
|
||||
while true; do
|
||||
if curl -fsS "http://localhost:8000/api/health" >/dev/null 2>&1; then
|
||||
echo "== stack: backend listo =="
|
||||
break
|
||||
fi
|
||||
i=$((i + 2))
|
||||
if [ "$i" -ge "$BACKEND_MAX_SEC" ]; then
|
||||
echo "ERROR: timeout esperando http://localhost:8000/api/health (${BACKEND_MAX_SEC}s)"
|
||||
exit 1
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
i=0
|
||||
while true; do
|
||||
if curl -fsS "http://localhost:5173/" >/dev/null 2>&1; then
|
||||
echo "== stack: frontend listo =="
|
||||
exit 0
|
||||
fi
|
||||
i=$((i + 2))
|
||||
if [ "$i" -ge "$FRONTEND_MAX_SEC" ]; then
|
||||
echo "ERROR: timeout esperando http://localhost:5173/ (${FRONTEND_MAX_SEC}s)"
|
||||
exit 1
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
STEP="${STEP:-5}"
|
||||
|
||||
wait_for() {
|
||||
local url="$1" max="$2" label="$3"
|
||||
echo "== wait: ${label} ${url} =="
|
||||
local i=0
|
||||
until curl -fsS --connect-timeout 3 --max-time 5 "$url" >/dev/null 2>&1; do
|
||||
i=$((i + STEP))
|
||||
if [ "$i" -ge "$max" ]; then
|
||||
echo "ERROR: timeout esperando ${label} ${url} (${max}s)"
|
||||
return 1
|
||||
fi
|
||||
if [ $((i % 30)) -eq 0 ]; then
|
||||
echo " ...esperando ${label} (${i}/${max}s)"
|
||||
fi
|
||||
sleep "$STEP"
|
||||
done
|
||||
echo "== ${label} listo tras ${i}s =="
|
||||
}
|
||||
|
||||
wait_for "$BACKEND_URL" "$BACKEND_MAX_SEC" "backend"
|
||||
wait_for "$FRONTEND_URL" "$FRONTEND_MAX_SEC" "frontend"
|
||||
|
||||
Reference in New Issue
Block a user