databuild/tests/end_to_end/podcast_simple_test.sh
2025-07-07 19:20:45 -07:00

127 lines
No EOL
3.8 KiB
Bash
Executable file

#!/bin/bash
# Simple end-to-end test for podcast reviews
set -euo pipefail
CLI_BUILD="${1:-}"
SERVICE_BINARY="${2:-}"
if [[ -z "$CLI_BUILD" ]] || [[ -z "$SERVICE_BINARY" ]]; then
echo "Usage: $0 <cli_build_binary> <service_binary>"
exit 1
fi
echo "[INFO] Testing CLI build for podcast reviews..."
export DATABUILD_BUILD_EVENT_LOG="sqlite:///tmp/podcast_test_cli.db"
rm -f /tmp/podcast_test_cli.db
# Test CLI build with a simple partition
if ! "$CLI_BUILD" "reviews/date=2020-01-01" > /tmp/podcast_cli_output.log 2>&1; then
echo "[ERROR] CLI build failed"
cat /tmp/podcast_cli_output.log
exit 1
fi
echo "[INFO] CLI build succeeded"
# Count events in CLI database
if [[ -f /tmp/podcast_test_cli.db ]]; then
CLI_EVENTS=$(sqlite3 /tmp/podcast_test_cli.db "SELECT COUNT(*) FROM build_events;" 2>/dev/null || echo "0")
echo "[INFO] CLI generated $CLI_EVENTS events"
else
echo "[ERROR] CLI database not created"
exit 1
fi
echo "[INFO] Testing Service build for podcast reviews..."
# The service uses a hardcoded database path
SERVICE_DB_PATH="/tmp/podcast_reviews_graph_service.db"
rm -f "$SERVICE_DB_PATH"
# Start service
SERVICE_PORT=58082
"$SERVICE_BINARY" --port="$SERVICE_PORT" --host="127.0.0.1" > /tmp/podcast_service.log 2>&1 &
SERVICE_PID=$!
# Cleanup service on exit
trap "kill $SERVICE_PID 2>/dev/null || true; wait $SERVICE_PID 2>/dev/null || true" EXIT
# Wait for service to start and test health
sleep 3
for i in {1..10}; do
if curl -s "http://127.0.0.1:$SERVICE_PORT/api/v1/builds" > /dev/null 2>&1; then
echo "[INFO] Service is healthy"
break
fi
if [[ $i -eq 10 ]]; then
echo "[ERROR] Service health check failed"
cat /tmp/podcast_service.log
exit 1
fi
sleep 1
done
# Make build request
BUILD_RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"partitions": ["reviews/date=2020-01-01"]}' \
"http://127.0.0.1:$SERVICE_PORT/api/v1/builds")
BUILD_ID=$(echo "$BUILD_RESPONSE" | jq -r '.build_request_id' 2>/dev/null || echo "")
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then
echo "[ERROR] Failed to get build ID: $BUILD_RESPONSE"
exit 1
fi
echo "[INFO] Created build request: $BUILD_ID"
# Wait for build completion
for i in {1..60}; do
STATUS_RESPONSE=$(curl -s "http://127.0.0.1:$SERVICE_PORT/api/v1/builds/$BUILD_ID")
STATUS=$(echo "$STATUS_RESPONSE" | jq -r '.status' 2>/dev/null || echo "UNKNOWN")
case "$STATUS" in
"completed"|"COMPLETED")
echo "[INFO] Service build completed"
break
;;
"failed"|"FAILED")
echo "[ERROR] Service build failed: $STATUS_RESPONSE"
exit 1
;;
"running"|"RUNNING"|"pending"|"PENDING"|"planning"|"PLANNING")
echo "[INFO] Build status: $STATUS"
sleep 2
;;
*)
echo "[WARN] Unknown status: $STATUS"
sleep 2
;;
esac
if [[ $i -eq 60 ]]; then
echo "[ERROR] Build did not complete within 120 seconds"
exit 1
fi
done
# Count events in Service database
if [[ -f "$SERVICE_DB_PATH" ]]; then
SERVICE_EVENTS=$(sqlite3 "$SERVICE_DB_PATH" "SELECT COUNT(*) FROM build_events;" 2>/dev/null || echo "0")
echo "[INFO] Service generated $SERVICE_EVENTS events"
else
echo "[ERROR] Service database not created"
exit 1
fi
# Compare event counts (should be similar)
if [[ "$CLI_EVENTS" -gt 0 ]] && [[ "$SERVICE_EVENTS" -gt 0 ]]; then
echo "[INFO] Both CLI and Service generated events successfully"
echo "[INFO] CLI: $CLI_EVENTS events, Service: $SERVICE_EVENTS events"
else
echo "[ERROR] One or both builds generated no events"
exit 1
fi
echo "[INFO] Podcast reviews simple end-to-end test completed successfully!"