mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
test(multiplayer): drive compose proposal orchestration
This commit is contained in:
@@ -94,6 +94,49 @@ curl -fsS -o /dev/null -X POST "$api_url/v1/queue/compose-queue-ticket/cancel" \
|
||||
-H 'Idempotency-Key: compose-cancel-key-123456' \
|
||||
-H "If-Match-Revision: $heartbeat_revision"
|
||||
|
||||
# Drive six independent authenticated players through the real queue boundary;
|
||||
# the matcher service consumes the durable rows below and creates the proposal.
|
||||
match_tokens=()
|
||||
for player in 1 2 3 4 5 6; do
|
||||
player_session="$(curl -fsS -X POST "$api_url/v1/session/steam" \
|
||||
-H 'Content-Type: application/json' -d "{\"web_api_ticket\":\"compose-match-player-${player}\"}")"
|
||||
match_tokens+=("$(python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])' <<<"$player_session")")
|
||||
curl -fsS -o /dev/null -X POST "$api_url/v1/queue" \
|
||||
-H "Authorization: Bearer ${match_tokens[$((player - 1))]}" \
|
||||
-H "Idempotency-Key: compose-match-queue-key-${player}-123456" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"ticket_id\":\"compose-match-ticket-${player}\",\"playlist\":\"casual\",\"client_build\":\"build-1\",\"protocol_version\":1}"
|
||||
done
|
||||
"${compose[@]}" exec -T database psql -v ON_ERROR_STOP=1 -U cosmic_clash_test -d cosmic_clash_test -c \
|
||||
"UPDATE queue_tickets SET predicted_rtt = '{\"EU\":30}'::jsonb WHERE ticket_id LIKE 'compose-match-ticket-%'" >/dev/null
|
||||
|
||||
proposal_id=""
|
||||
for attempt in $(seq 1 30); do
|
||||
proposal_id="$("${compose[@]}" exec -T database psql -At -U cosmic_clash_test -d cosmic_clash_test -c "SELECT proposal_id FROM proposals WHERE state = 'OPEN' ORDER BY created_at DESC LIMIT 1" | tr -d '\r')"
|
||||
if [[ -n "$proposal_id" ]]; then break; fi
|
||||
[[ "$attempt" == 30 ]] && { echo "matcher did not create a proposal" >&2; exit 1; }
|
||||
sleep 1
|
||||
done
|
||||
proposal_json="$(curl -fsS -H "Authorization: Bearer ${match_tokens[0]}" "$api_url/v1/proposals/$proposal_id")"
|
||||
python3 - "$proposal_json" <<'PY'
|
||||
import json, sys
|
||||
proposal = json.loads(sys.argv[1])
|
||||
assert proposal["state"] == "OPEN"
|
||||
assert len(proposal["participants"]) == 6
|
||||
print("proposal formation check passed")
|
||||
PY
|
||||
|
||||
proposal_revision=0
|
||||
for player in 1 2 3 4 5 6; do
|
||||
proposal_json="$(curl -fsS -X POST "$api_url/v1/proposals/$proposal_id/accept" \
|
||||
-H "Authorization: Bearer ${match_tokens[$((player - 1))]}" \
|
||||
-H "Idempotency-Key: compose-proposal-accept-${player}-123456" \
|
||||
-H "If-Match-Revision: $proposal_revision")"
|
||||
proposal_revision="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["revision"])' <<<"$proposal_json")"
|
||||
done
|
||||
[[ "$("${compose[@]}" exec -T database psql -At -U cosmic_clash_test -d cosmic_clash_test -c "SELECT state FROM proposals WHERE proposal_id = '$proposal_id'" | tr -d '\r')" == ACCEPTED ]]
|
||||
[[ "$("${compose[@]}" exec -T database psql -At -U cosmic_clash_test -d cosmic_clash_test -c "SELECT count(*) FROM matches WHERE state = 'ALLOCATING'" | tr -d '\r')" == 1 ]]
|
||||
|
||||
# Model the durable state produced by the allocator, then use the real HTTP
|
||||
# workload authentication and mutation boundaries for every action below.
|
||||
"${compose[@]}" exec -T database psql -v ON_ERROR_STOP=1 -U cosmic_clash_test -d cosmic_clash_test <<'SQL'
|
||||
|
||||
Reference in New Issue
Block a user