databuild/tests/end_to_end/podcast_simple_test.sh

163 lines
No EOL
6.3 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 with its own database
export DATABUILD_BUILD_EVENT_LOG="sqlite://$SERVICE_DB_PATH"
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_name' 2>/dev/null || echo "UNKNOWN")
case "$STATUS" in
"completed"|"COMPLETED"|"BuildRequestCompleted")
echo "[INFO] Service build completed"
break
;;
"failed"|"FAILED"|"BuildRequestFailed")
echo "[ERROR] Service build failed: $STATUS_RESPONSE"
exit 1
;;
"running"|"RUNNING"|"pending"|"PENDING"|"planning"|"PLANNING"|"executing"|"EXECUTING"|"BuildRequestPlanning"|"BuildRequestExecuting"|"BuildRequestReceived")
echo "[INFO] Build status: $STATUS"
sleep 2
;;
*)
echo "[WARN] Unknown status: $STATUS"
exit 1
;;
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 with detailed analysis
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"
# Detailed event comparison
echo "[INFO] Analyzing event distribution..."
CLI_JOB_EVENTS=$(sqlite3 /tmp/podcast_test_cli.db "SELECT COUNT(*) FROM build_events WHERE event_type = 'job';" 2>/dev/null || echo "0")
CLI_PARTITION_EVENTS=$(sqlite3 /tmp/podcast_test_cli.db "SELECT COUNT(*) FROM build_events WHERE event_type = 'partition';" 2>/dev/null || echo "0")
CLI_REQUEST_EVENTS=$(sqlite3 /tmp/podcast_test_cli.db "SELECT COUNT(*) FROM build_events WHERE event_type = 'build_request';" 2>/dev/null || echo "0")
SERVICE_JOB_EVENTS=$(sqlite3 "$SERVICE_DB_PATH" "SELECT COUNT(*) FROM build_events WHERE event_type = 'job';" 2>/dev/null || echo "0")
SERVICE_PARTITION_EVENTS=$(sqlite3 "$SERVICE_DB_PATH" "SELECT COUNT(*) FROM build_events WHERE event_type = 'partition';" 2>/dev/null || echo "0")
SERVICE_REQUEST_EVENTS=$(sqlite3 "$SERVICE_DB_PATH" "SELECT COUNT(*) FROM build_events WHERE event_type = 'build_request';" 2>/dev/null || echo "0")
echo "[INFO] Event breakdown:"
echo "[INFO] Job events: CLI=$CLI_JOB_EVENTS, Service=$SERVICE_JOB_EVENTS"
echo "[INFO] Partition events: CLI=$CLI_PARTITION_EVENTS, Service=$SERVICE_PARTITION_EVENTS"
echo "[INFO] Request events: CLI=$CLI_REQUEST_EVENTS, Service=$SERVICE_REQUEST_EVENTS"
# Validate that CLI and Service produce identical event patterns
if [[ "$CLI_JOB_EVENTS" -eq "$SERVICE_JOB_EVENTS" ]] && [[ "$CLI_PARTITION_EVENTS" -eq "$SERVICE_PARTITION_EVENTS" ]] && [[ "$CLI_REQUEST_EVENTS" -eq "$SERVICE_REQUEST_EVENTS" ]]; then
echo "[INFO] ✅ Core build events (job, partition, and request) are identical"
else
echo "[ERROR] ❌ Core build events differ - CLI and Service should produce identical events"
echo "[ERROR] This indicates the CLI is not properly coordinating analysis and execution phases"
exit 1
fi
# Validate total event counts are identical
if [[ "$CLI_EVENTS" -eq "$SERVICE_EVENTS" ]]; then
echo "[INFO] ✅ Total event counts are identical: $CLI_EVENTS events each"
else
echo "[ERROR] ❌ Total event counts differ: CLI=$CLI_EVENTS, Service=$SERVICE_EVENTS"
echo "[ERROR] CLI and Service should produce identical event patterns for the same operations"
exit 1
fi
else
echo "[ERROR] One or both builds generated no events"
exit 1
fi
echo "[INFO] Podcast reviews simple end-to-end test completed successfully!"