Repository navigation
Expand file tree
/
Copy pathrun-e2e.sh
More file actions
executable file
·73 lines (64 loc) · 2.56 KB
/
Copy pathrun-e2e.sh
File metadata and controls
executable file
·73 lines (64 loc) · 2.56 KB
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 -e
cd "$(dirname "$0")"
# In a worktree, load the unique compose project name and host ports.
# Values already exported in the environment win over .env.worktree.
if [ -f .env.worktree ]; then
while IFS='=' read -r key value; do
case "$key" in ''|\#*) continue ;; esac
if [ -z "${!key+x}" ]; then
export "$key=$value"
fi
done < .env.worktree
fi
RABBITMQ_HOST="${RABBITMQ_HOST:-127.0.0.1}"
RABBITMQ_PORT="${RABBITMQ_PORT:-5552}"
RABBITMQ_MANAGEMENT_PORT="${RABBITMQ_MANAGEMENT_PORT:-15672}"
export RABBITMQ_HOST RABBITMQ_PORT RABBITMQ_MANAGEMENT_PORT
# Health-wait bounds: E2E_HEALTH_RETRIES polls, E2E_HEALTH_INTERVAL seconds apart.
# The defaults cap the wait at three minutes instead of polling forever (#472).
HEALTH_RETRIES="${E2E_HEALTH_RETRIES:-90}"
HEALTH_INTERVAL="${E2E_HEALTH_INTERVAL:-2}"
cleanup() {
echo "Stopping RabbitMQ..."
docker compose down
}
trap cleanup EXIT
echo "Starting RabbitMQ..."
docker compose up -d
echo "Waiting for RabbitMQ to be healthy..."
# Resolve the container from the compose project (a worktree sets COMPOSE_PROJECT_NAME),
# never from a fixed container name, so remapped ports and parallel worktrees keep working.
container_id="$(docker compose ps -q rabbitmq || true)"
if [ -z "$container_id" ]; then
echo "ERROR: 'docker compose up -d' started no 'rabbitmq' container." >&2
exit 1
fi
# `docker inspect` reads the health status directly: no host `python3` and no dependency
# on the JSON shape `docker compose ps --format json` happens to emit (#472).
status=""
attempt=0
while [ "$attempt" -lt "$HEALTH_RETRIES" ]; do
attempt=$((attempt + 1))
status="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id" 2>/dev/null || echo unknown)"
if [ "$status" = "healthy" ]; then
break
fi
echo -n "."
sleep "$HEALTH_INTERVAL"
done
if [ "$status" != "healthy" ]; then
echo ""
echo "ERROR: RabbitMQ is not healthy after ${attempt} poll(s) (${HEALTH_INTERVAL}s apart); last status: '${status}'." >&2
echo "--- docker compose logs --tail=50 rabbitmq ---" >&2
docker compose logs --tail=50 rabbitmq >&2 || true
exit 1
fi
echo ""
echo "RabbitMQ is ready."
echo "Creating test stream..."
curl -sf -u guest:guest -X PUT "http://${RABBITMQ_HOST}:${RABBITMQ_MANAGEMENT_PORT}/api/queues/%2F/test-stream" \
-H "Content-Type: application/json" \
-d '{"durable":true,"arguments":{"x-queue-type":"stream"}}' || true
echo "Running E2E tests..."
./vendor/bin/phpunit --testsuite e2e --testdox