#!/bin/bash # Doltgresql compatibility test runner. # # Downloads specified doltgresql release binaries, creates test repositories # using them, and runs BATS test suites to verify backward, forward, and # bidirectional compatibility. # # Usage: ./runner.sh # Run from the integration-tests/compatibility directory. # # Environment variables (optional): # DOLTGRES_SKIP_BACKWARD — skip backward-compatibility tests if set # DOLTGRES_SKIP_FORWARD — skip forward-compatibility tests if set # DOLTGRES_SKIP_BIDIR — skip bidirectional-compatibility tests if set set -eo pipefail PLATFORM_TUPLE="" # --------------------------------------------------------------------------- # Platform detection # --------------------------------------------------------------------------- get_platform_tuple() { local OS ARCH OS=$(uname) ARCH=$(uname -m) if [ "$OS" != Linux ] && [ "$OS" != Darwin ]; then echo "tests only support linux or macOS." >&2 exit 1 fi if [ "$OS" = Linux ]; then PLATFORM_TUPLE=linux else PLATFORM_TUPLE=darwin fi if [ "$ARCH" = x86_64 ]; then PLATFORM_TUPLE="${PLATFORM_TUPLE}-amd64" elif [ "$ARCH" = arm64 ] || [ "$ARCH" = aarch64 ]; then PLATFORM_TUPLE="${PLATFORM_TUPLE}-arm64" else echo "unsupported architecture: $ARCH" >&2 exit 1 fi echo "$PLATFORM_TUPLE" } # --------------------------------------------------------------------------- # Release download # --------------------------------------------------------------------------- # download_release # Downloads doltgresql-.tar.gz for the given version tag, extracts it # into binaries//, and prints the path to the bin directory. download_release() { local ver="$1" local dirname="binaries/$ver" mkdir -p "$dirname" local basename="doltgresql-${PLATFORM_TUPLE}" local filename="${basename}.tar.gz" local filepath="${dirname}/${filename}" local url="https://github.com/dolthub/doltgresql/releases/download/${ver}/${filename}" echo "Downloading doltgresql ${ver} for ${PLATFORM_TUPLE} ..." >&2 curl -L -o "$filepath" "$url" tar -zxf "$filepath" -C "$dirname" # Binary lives at doltgresql--/bin/doltgres echo "${dirname}/${basename}/bin" } # --------------------------------------------------------------------------- # Server management helpers used by the runner (not BATS) # --------------------------------------------------------------------------- _pick_port() { for i in {0..99}; do local port=$((RANDOM % 4096 + 2048)) if ! nc -z localhost "$port" 2>/dev/null; then echo "$port" return 0 fi done echo "ERROR: could not find a free port" >&2 return 1 } _write_config() { local dir="$1" port="$2" cat > "$dir/runner-config.yaml" < → sets RUNNER_SERVER_PID and RUNNER_SERVER_PORT start_server() { local binary="$1" datadir="$2" logfile="$3" RUNNER_SERVER_PORT=$(_pick_port) _write_config "$datadir" "$RUNNER_SERVER_PORT" PGPASSWORD=password "$binary" -data-dir="$datadir" \ --config="$datadir/runner-config.yaml" > "$logfile" 2>&1 & RUNNER_SERVER_PID=$! local end=$((SECONDS + 20)) while [ $SECONDS -lt $end ]; do if PGPASSWORD=password psql -U postgres -h localhost -p "$RUNNER_SERVER_PORT" \ -c "SELECT 1;" postgres >/dev/null 2>&1; then return 0 fi sleep 0.5 done echo "ERROR: server failed to start on port $RUNNER_SERVER_PORT" >&2 cat "$logfile" >&2 kill "$RUNNER_SERVER_PID" 2>/dev/null return 1 } stop_server() { if [ -n "$RUNNER_SERVER_PID" ]; then kill "$RUNNER_SERVER_PID" 2>/dev/null || true wait "$RUNNER_SERVER_PID" 2>/dev/null || true RUNNER_SERVER_PID="" RUNNER_SERVER_PORT="" fi } RUNNER_SERVER_PID="" RUNNER_SERVER_PORT="" # --------------------------------------------------------------------------- # Repository setup # --------------------------------------------------------------------------- # setup_repo