172 lines
No EOL
6.6 KiB
Bash
Executable file
172 lines
No EOL
6.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Simple end-to-end test for basic functionality
|
|
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..."
|
|
# Clean up any existing partition state and databases to prevent delegation
|
|
rm -f /tmp/simple_test_cli.db /tmp/basic_graph_service.db
|
|
rm -f /tmp/*generated_number* 2>/dev/null || true
|
|
# Kill any existing service processes that might hold database locks
|
|
killall basic_graph.service 2>/dev/null || true
|
|
killall build_graph_service 2>/dev/null || true
|
|
sleep 1
|
|
export DATABUILD_BUILD_EVENT_LOG="sqlite:///tmp/simple_test_cli.db"
|
|
|
|
# Test CLI build
|
|
if ! "$CLI_BUILD" "generated_number/pippin" > /tmp/cli_output.log 2>&1; then
|
|
echo "[ERROR] CLI build failed"
|
|
cat /tmp/cli_output.log
|
|
exit 1
|
|
fi
|
|
|
|
echo "[INFO] CLI build succeeded"
|
|
|
|
# Count events in CLI database
|
|
if [[ -f /tmp/simple_test_cli.db ]]; then
|
|
CLI_EVENTS=$(sqlite3 /tmp/simple_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..."
|
|
# The service uses a hardcoded database path
|
|
SERVICE_DB_PATH="/tmp/basic_graph_service.db"
|
|
# Clean up service database (already cleaned above, but being explicit)
|
|
rm -f "$SERVICE_DB_PATH"
|
|
|
|
# Start service with its own database
|
|
export DATABUILD_BUILD_EVENT_LOG="sqlite://$SERVICE_DB_PATH"
|
|
SERVICE_PORT=58080
|
|
"$SERVICE_BINARY" --port="$SERVICE_PORT" --host="127.0.0.1" > /tmp/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
|
|
sleep 3
|
|
|
|
# Test service health by trying to connect to the port
|
|
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/service.log
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Make build request
|
|
BUILD_RESPONSE=$(curl -s -X POST \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"partitions": ["generated_number/pippin"]}' \
|
|
"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..30}; 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 30 ]]; then
|
|
echo "[ERROR] Build did not complete within 60 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/simple_test_cli.db "SELECT COUNT(*) FROM build_events WHERE event_type = 'job';" 2>/dev/null || echo "0")
|
|
CLI_PARTITION_EVENTS=$(sqlite3 /tmp/simple_test_cli.db "SELECT COUNT(*) FROM build_events WHERE event_type = 'partition';" 2>/dev/null || echo "0")
|
|
CLI_REQUEST_EVENTS=$(sqlite3 /tmp/simple_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] Simple end-to-end test completed successfully!" |