File size: 2,250 Bytes
6d528b3 | 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 | #!/usr/bin/env bash
set -euo pipefail
SUFFIX="${RANDOM}${RANDOM}"
CONTAINER="matchday-memory-concurrency-$SUFFIX"
DB_TEST_VALUE="local-memory-test-$SUFFIX"
VENV_DIR="$(mktemp -d "${TMPDIR:-/tmp}/matchday-memory-test.XXXXXX")"
PORT="$(python3 -c 'import socket; sock = socket.socket(); sock.bind(("127.0.0.1", 0)); print(sock.getsockname()[1]); sock.close()')"
cleanup() {
docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
rm -rf "$VENV_DIR"
}
trap cleanup EXIT INT TERM
docker run -d --name "$CONTAINER" \
-p "127.0.0.1:${PORT}:5432" \
-e "POSTGRES_PASSWORD=$DB_TEST_VALUE" \
-e POSTGRES_USER=matchday \
-e POSTGRES_DB=matchday_test \
postgres:16-alpine >/dev/null
for _ in $(seq 1 60); do
ready_markers="$(docker logs "$CONTAINER" 2>&1 | grep -c 'database system is ready to accept connections' || true)"
if [[ "$ready_markers" -ge 2 ]] && \
docker exec "$CONTAINER" pg_isready -U matchday -d matchday_test >/dev/null 2>&1; then
break
fi
sleep 0.25
done
docker exec "$CONTAINER" pg_isready -U matchday -d matchday_test >/dev/null
python3 -m venv "$VENV_DIR/venv"
"$VENV_DIR/venv/bin/pip" install --quiet -e '.[postgres,dev]'
MATCHDAY_TEST_POSTGRES_URL="postgresql+psycopg://matchday:${DB_TEST_VALUE}@127.0.0.1:${PORT}/matchday_test" \
PYTHONPATH=backend \
"$VENV_DIR/venv/bin/python" -m pytest \
backend/tests/test_hardening_regressions.py::test_concurrent_postgres_writes_leave_exactly_one_active_memory \
backend/tests/test_hardening_regressions.py::test_concurrent_postgres_share_requests_reuse_one_artifact \
backend/tests/test_hardening_regressions.py::test_concurrent_postgres_share_upgrade_creates_one_v2_artifact \
backend/tests/test_hardening_regressions.py::test_postgres_run_heartbeat_does_not_deadlock_agent_checkpoint \
backend/tests/test_hardening_regressions.py::test_postgres_safe_reads_do_not_write_nonces_and_mutation_replay_is_atomic \
backend/tests/test_hardening_regressions.py::test_concurrent_postgres_run_budget_reservations_enforce_both_limits \
backend/tests/test_hardening_regressions.py::test_concurrent_postgres_resume_claim_has_exactly_one_winner \
backend/tests/test_hardening_regressions.py::test_postgres_tool_charge_survives_outer_transaction_rollback \
-q
|