#!/usr/bin/env bash # run-tests.sh — runs the backend test suite behind an advisory lockfile. # # WHY: every test package drops/recreates a FIXED test database name # (crussell_test_handlers_payments, crussell_test_internal_square, etc.) in its # TestMain. Two concurrent `go test` invocations targeting the same package # therefore destroy each other's database mid-run (SQLSTATE 3D000 / 57P01 # "terminating connection due to administrator command"). This wrapper # serializes runs on a flock(1) lockfile so the test DBs are never clobbered. # # USAGE: # ./run-tests.sh [go test args...] # e.g. ./run-tests.sh -tags "test,dev" -count=1 -parallel 8 ./... # LOCK_TIMEOUT=600 ./run-tests.sh ... # max wait for the lock (default 300s) # # Agents and humans: ALWAYS run backend tests through this script (or take the # lockfile yourself: `flock /tmp/crussell-tests.lock -c ''`). set -u LOCKFILE="${LOCKFILE:-/tmp/crussell-tests.lock}" LOCK_TIMEOUT="${LOCK_TIMEOUT:-300}" cd "$(dirname "$0")" exec flock -w "$LOCK_TIMEOUT" "$LOCKFILE" go test "$@"