Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 56 additions & 11 deletions .github/workflows/spockbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,62 @@ jobs:
--build-arg PGVER=${{ matrix.pgver }} \
-t spock -f tests/docker/Dockerfile-step-1.el9 .

- name: Start docker
run: |
cd ${GITHUB_WORKSPACE}/tests/docker/
echo PG_VER=${{ matrix.pgver }} >> pgedge.env
docker compose build --build-arg PGVER=${{ matrix.pgver }}
docker compose up

- name: Check spockbench output
run: |
cd ${GITHUB_WORKSPACE}/tests/docker
./check-outputs.sh

- name: Collect Spockbench artifacts (logs and configs)
if: ${{ always() }}
run: |
mkdir -p ${GITHUB_WORKSPACE}/spockbench-artifacts
cd ${GITHUB_WORKSPACE}/tests/docker/

# Collect from all containers (even stopped ones)
for container in n1 n2 n3; do
echo "Collecting artifacts from $container"

# Copy PostgreSQL logfile
docker cp "$container":/home/pgedge/pgedge/data/pg${{ matrix.pgver }}/logfile \
"${GITHUB_WORKSPACE}/spockbench-artifacts/${container}-logfile.log" 2>/dev/null || \
echo "Warning: No logfile in $container"

# Copy postgresql.conf
docker cp "$container":/home/pgedge/pgedge/data/pg${{ matrix.pgver }}/postgresql.conf \
"${GITHUB_WORKSPACE}/spockbench-artifacts/${container}-postgresql.conf" 2>/dev/null || \
echo "Warning: No postgresql.conf in $container"

# Copy docker container logs
docker logs "$container" > "${GITHUB_WORKSPACE}/spockbench-artifacts/${container}-docker.log" 2>&1 || \
echo "Warning: Could not get docker logs for $container"
done

# List what we collected
echo "Collected artifacts:"
ls -lah ${GITHUB_WORKSPACE}/spockbench-artifacts/ || echo "No artifacts collected"

- name: Upload Spockbench artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: spockbench-${{ matrix.pgver }}
path: spockbench-artifacts/**
if-no-files-found: ignore
retention-days: 7

- name: Stop Spockbench containers
if: ${{ always() }}
run: |
cd ${GITHUB_WORKSPACE}/tests/docker/
docker compose down -v || true

- name: Run regression tests
run: |
REG_CT_NAME="spock-regress-${{ matrix.pgver }}-${{ github.run_id }}-${{ github.run_attempt }}"
Expand Down Expand Up @@ -104,14 +160,3 @@ jobs:
if-no-files-found: ignore
retention-days: 7

- name: Start docker
run: |
cd ${GITHUB_WORKSPACE}/tests/docker/
echo PG_VER=${{ matrix.pgver }} >> pgedge.env
docker compose up

- name: Check spockbench output
run: |
cd ${GITHUB_WORKSPACE}/tests/docker
./check-outputs.sh

9 changes: 5 additions & 4 deletions tests/docker/Dockerfile-step-1.el9
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ ENV PGVER=$PGVER
ENV PATH="/home/pgedge/pgedge/pg${PGVER}/bin:${PATH}"
ENV LD_LIBRARY_PATH="/home/pgedge/pgedge/pg${PGVER}/lib:${LD_LIBRARY_PATH}"
ENV PG_CONFIG="/home/pgedge/pgedge/pg${PGVER}/bin/pg_config"
ENV SPOCK_SOURCE_DIR="/home/pgedge/spock"

# Copy spock source code and set proper ownership
COPY . /home/pgedge/spock
RUN chown -R pgedge:pgedge /home/pgedge/spock
COPY . ${SPOCK_SOURCE_DIR}
RUN chown -R pgedge:pgedge ${SPOCK_SOURCE_DIR}

WORKDIR /home/pgedge

Expand All @@ -37,7 +38,7 @@ RUN echo "Setting up pgedge..." && \

WORKDIR /home/pgedge/postgres

RUN for patchfile in /home/pgedge/spock/patches/${PGVER}/*; do \
RUN for patchfile in ${SPOCK_SOURCE_DIR}/patches/${PGVER}/*; do \
patch -p1 --verbose < $patchfile; \
done

Expand Down Expand Up @@ -72,7 +73,7 @@ RUN echo "==========Compiling Modified PostgreSQL==========" && \
make -C contrib install

# Compile Spock
WORKDIR /home/pgedge/spock
WORKDIR ${SPOCK_SOURCE_DIR}
RUN echo "==========Compiling Spock==========" && \
make clean && \
make -j${MAKE_JOBS} && \
Expand Down
27 changes: 26 additions & 1 deletion tests/docker/check-outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,36 @@ set -euo pipefail

containers=$(docker ps -aq --filter "label=com.docker.compose.project=tests");

if [ -z "$containers" ]; then
echo "FAIL: No containers found with label 'com.docker.compose.project=tests'"
exit 1
fi

for cid in $containers; do
name=$(docker inspect -f '{{ .Name }}' "$cid" | sed 's|/||')
exit_code=$(docker inspect -f '{{ .State.ExitCode }}' "$cid")

# Check exit code
if [ "$exit_code" -ne 0 ]; then
name=$(docker inspect -f '{{ .Name }}' "$cid" | sed 's|/||')
echo "FAIL: Container '$name' exited with code $exit_code"
docker logs "$cid" 2>&1 | tail -50
exit 1
fi

# Check PostgreSQL logs for errors
if docker exec "$cid" test -d /home/pgedge/pgedge/data 2>/dev/null; then
pg_log=$(docker exec "$cid" find /home/pgedge/pgedge/data -name "postgresql-*.log" -o -name "*.log" 2>/dev/null | head -1)
if [ -n "$pg_log" ]; then
error_count=$(docker exec "$cid" grep -i "ERROR:" "$pg_log" 2>/dev/null | grep -v "ERROR: relation.*does not exist" | wc -l || echo 0)
if [ "$error_count" -gt 0 ]; then
echo "FAIL: Container '$name' has $error_count ERROR(s) in PostgreSQL logs"
docker exec "$cid" grep -i "ERROR:" "$pg_log" | grep -v "ERROR: relation.*does not exist" | tail -20
exit 1
fi
fi
fi

echo "✓ Container '$name' passed all checks"
done

echo "✓ All containers passed validation"
10 changes: 8 additions & 2 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
hostname: n1
image: spock
build:
context: .
dockerfile: Dockerfile-step-1.el9
context: ../..
dockerfile: tests/docker/Dockerfile-step-1.el9
environment:
- HOSTNAME=n1
- PEER_NAMES=n2,n3
Expand All @@ -23,6 +23,9 @@ services:
container_name: n2
hostname: n2
image: spock
build:
context: ../..
dockerfile: tests/docker/Dockerfile-step-1.el9
environment:
- HOSTNAME=n2
- PEER_NAMES=n1,n3
Expand All @@ -40,6 +43,9 @@ services:
container_name: n3
hostname: n3
image: spock
build:
context: ../..
dockerfile: tests/docker/Dockerfile-step-1.el9
environment:
- HOSTNAME=n3
- PEER_NAMES=n1,n2
Expand Down
84 changes: 72 additions & 12 deletions tests/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,94 @@ function wait_for_pg()
done
}

. /home/pgedge/pgedge/pg$PGVER/pg$PGVER.env
. /home/pgedge/.bashrc

echo "==========Installing Spockbench=========="
cd ~/spockbench
sudo python3 setup.py install

cd ~/pgedge
sed -i '/log_min_messages/s/^#//g' data/pg$PGVER/postgresql.conf
sed -i -e '/log_min_messages =/ s/= .*/= debug1/' data/pg$PGVER/postgresql.conf
./pgedge restart

wait_for_pg
# Initialize PostgreSQL if not already done
if [ ! -d "data/pg$PGVER" ]; then
echo "==========Initializing PostgreSQL $PGVER=========="

# Initialize the database cluster
pg${PGVER}/bin/initdb -D data/pg${PGVER} --encoding=UTF8 --locale=C

# Configure PostgreSQL with settings from regress-postgresql.conf
cat >> data/pg${PGVER}/postgresql.conf <<EOF

# Spock configuration
shared_preload_libraries = 'spock'
wal_level = logical
max_wal_senders = 20
max_replication_slots = 20
max_worker_processes = 20
track_commit_timestamp = on
max_locks_per_transaction = 1000

# Connection settings
unix_socket_directories = '/tmp'
listen_addresses = '*'
port = 5432

# Logging
log_line_prefix = '[%m] [%p] [%d] '
log_min_messages = debug1

# Performance (for testing)
fsync = off

# Spock settings
spock.synchronous_commit = true
EOF

# Configure pg_hba.conf for network access
cat >> data/pg${PGVER}/pg_hba.conf <<EOF

# Allow replication connections
host replication all 0.0.0.0/0 trust
host all all 0.0.0.0/0 trust
EOF

# Start PostgreSQL
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} -l data/pg${PGVER}/logfile start

wait_for_pg

# Create database and user
export DBUSER=${DBUSER:-pgedge}
export DBNAME=${DBNAME:-demo}

pg${PGVER}/bin/createuser -h /tmp -s $DBUSER 2>/dev/null || true
pg${PGVER}/bin/createdb -h /tmp -O $DBUSER $DBNAME 2>/dev/null || true

echo "==========PostgreSQL $PGVER initialized successfully=========="
else
# PostgreSQL already initialized, just start it
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} -l data/pg${PGVER}/logfile start
wait_for_pg
fi

# Ensure environment variables are set
export DBUSER=${DBUSER:-pgedge}
export DBNAME=${DBNAME:-demo}

psql -h /tmp -U $DBUSER -d $DBNAME -c "drop extension spock;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "drop schema public cascade;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "create schema public;"
psql -h /tmp -U $DBUSER -d $DBNAME -c "create extension spock;"
# This code executes on a fresh system that means we have a clean Postgres
# instance.
psql -h /tmp -U $DBUSER -d $DBNAME -c "CREATE EXTENSION spock;"

./pgedge restart
# Restart PostgreSQL to apply all settings
pg${PGVER}/bin/pg_ctl -D data/pg${PGVER} restart -l data/pg${PGVER}/logfile

wait_for_pg

echo "==========Assert Spock version is the latest=========="
expected_line=$(grep '#define SPOCK_VERSION' /home/pgedge/spock/spock.h)
expected_line=$(grep '#define SPOCK_VERSION' ${SPOCK_SOURCE_DIR}/include/spock.h)
expected_version=$(echo "$expected_line" | grep -oP '"\K[0-9]+\.[0-9]+\.[0-9]+')
expected_major=${expected_version%%.*}
actual_version=$(psql -U $DBUSER -d $DBNAME -X -t -A -c "select spock.spock_version()")
actual_version=$(psql -U $DBUSER -d $DBNAME -X -t -A -c "SELECT spock.spock_version()")
actual_major=${actual_version%%.*}

if (( actual_major >= expected_major )); then
Expand Down
Loading
Loading