summaryrefslogtreecommitdiff
path: root/scripts/e2e-test.sh
blob: 9ec7cf94b80ef792781428dd2c6dee131e038d17 (plain)
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
#!/usr/bin/env bash
set -euo pipefail

COMPOSE="docker compose"
TIMEOUT=60

echo "=== Starting infrastructure ==="
$COMPOSE up -d redis postgres
sleep 5

echo "=== Running migrations ==="
cd shared && alembic upgrade head && cd ..

echo "=== Starting services ==="
$COMPOSE up -d data-collector strategy-engine order-executor portfolio-manager

echo "=== Waiting for services to be healthy ==="
services=("data-collector" "strategy-engine" "order-executor" "portfolio-manager")
for svc in "${services[@]}"; do
    echo -n "Waiting for $svc..."
    elapsed=0
    while [ $elapsed -lt $TIMEOUT ]; do
        status=$($COMPOSE ps --format json "$svc" 2>/dev/null | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('Health',''))" 2>/dev/null || echo "")
        if [ "$status" = "healthy" ]; then
            echo " OK"
            break
        fi
        sleep 2
        elapsed=$((elapsed + 2))
        echo -n "."
    done
    if [ $elapsed -ge $TIMEOUT ]; then
        echo " TIMEOUT"
        echo "=== Logs for $svc ==="
        $COMPOSE logs --tail=50 "$svc"
        $COMPOSE down
        exit 1
    fi
done

echo "=== Health check endpoints ==="
ports=(8080 8081 8082 8083)
names=("data-collector" "strategy-engine" "order-executor" "portfolio-manager")
for i in "${!ports[@]}"; do
    echo -n "  ${names[$i]} (${ports[$i]}): "
    status=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${ports[$i]}/health" 2>/dev/null || echo "000")
    if [ "$status" = "200" ] || [ "$status" = "503" ]; then
        echo "OK ($status)"
    else
        echo "FAIL ($status)"
    fi
done

echo "=== Metrics endpoints ==="
for i in "${!ports[@]}"; do
    echo -n "  ${names[$i]} (${ports[$i]}): "
    body=$(curl -s "http://localhost:${ports[$i]}/metrics" 2>/dev/null || echo "")
    if echo "$body" | grep -q "# HELP"; then
        echo "OK (Prometheus metrics found)"
    else
        echo "FAIL (no metrics)"
    fi
done

echo "=== Smoke test: Redis streams exist ==="
streams=$($COMPOSE exec -T redis redis-cli KEYS "candles.*" 2>/dev/null || echo "")
echo "  Redis streams: ${streams:-none yet (normal if no data flowing)}"

echo "=== Cleanup ==="
$COMPOSE down

echo ""
echo "=== E2E test complete ==="