Skip to content
Merged
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
51 changes: 41 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,58 @@ jobs:
- name: Download dependencies
run: go mod download

- name: Start PostgreSQL with logical replication
- name: Create Docker network
run: docker network create wal-test-network

- name: Start primary PostgreSQL (upstream)
run: |
docker run -d \
--name postgres-test \
--name postgres-primary \
--network wal-test-network \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
postgres:17 \
-c wal_level=logical \
-c max_wal_senders=10 \
-c max_replication_slots=10
-c max_wal_senders=20 \
-c max_replication_slots=20

- name: Start downstream PostgreSQL (for foreign origin testing)
run: |
docker run -d \
--name postgres-downstream \
--network wal-test-network \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 5433:5432 \
postgres:17 \
-c wal_level=logical \
-c max_wal_senders=20 \
-c max_replication_slots=20

- name: Wait for PostgreSQL to be ready
- name: Wait for PostgreSQL instances to be ready
run: |
for i in {1..30}; do
docker exec postgres-test pg_isready -U postgres && break
echo "Waiting for PostgreSQL..."
docker exec postgres-primary pg_isready -U postgres && break
echo "Waiting for primary PostgreSQL..."
sleep 2
done
for i in {1..30}; do
docker exec postgres-downstream pg_isready -U postgres && break
echo "Waiting for downstream PostgreSQL..."
sleep 2
done

- name: Verify PostgreSQL configuration
run: |
docker exec postgres-test psql -U postgres -c "SHOW wal_level;"
docker exec postgres-test psql -U postgres -c "SHOW max_replication_slots;"
docker exec postgres-test psql -U postgres -c "SHOW max_wal_senders;"
echo "=== Primary PostgreSQL ==="
docker exec postgres-primary psql -U postgres -c "SHOW wal_level;"
docker exec postgres-primary psql -U postgres -c "SHOW max_replication_slots;"
echo "=== Downstream PostgreSQL ==="
docker exec postgres-downstream psql -U postgres -c "SHOW wal_level;"
docker exec postgres-downstream psql -U postgres -c "SHOW max_replication_slots;"

- name: Run integration tests
env:
Expand All @@ -93,4 +119,9 @@ jobs:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_DOWNSTREAM_HOST: localhost
POSTGRES_DOWNSTREAM_PORT: 5433
# Internal hostnames for container-to-container communication (used by subscriptions)
POSTGRES_PRIMARY_HOST_INTERNAL: postgres-primary
POSTGRES_PRIMARY_PORT_INTERNAL: 5432
run: go test -v -tags=integration -timeout=300s ./listener/...
35 changes: 19 additions & 16 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ x-postgres-common:
user: postgres
restart: always
healthcheck:
test: 'pg_isready -U postgres --dbname=my_db'
test: 'pg_isready -U postgres --dbname=postgres'
interval: 10s
timeout: 5s
retries: 5

services:
# Primary PostgreSQL - the "upstream" database
# This is where we make changes that get replicated to the downstream
postgres_primary:
<<: *postgres-common
ports:
Expand All @@ -29,30 +31,31 @@ services:
postgres
-c wal_level=logical
-c hot_standby=on
-c max_wal_senders=10
-c max_replication_slots=10
-c max_wal_senders=20
-c max_replication_slots=20
-c hot_standby_feedback=on
volumes:
- ./scripts:/docker-entrypoint-initdb.d

postgres_replica:
# Downstream PostgreSQL - receives logical replication from primary
# wal-listener connects here to test foreign origin filtering
postgres_downstream:
<<: *postgres-common
ports:
- 5433:5432
environment:
PGUSER: replicator
PGPASSWORD: replicator_password
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5"
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
command: |
bash -c "
until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=replication_slot --host=postgres_primary --port=5432
do
echo 'Waiting for primary to connect...'
sleep 1s
done
echo 'Backup done, starting replica...'
chmod 0700 /var/lib/postgresql/data
postgres
"
postgres
-c wal_level=logical
-c hot_standby=on
-c max_wal_senders=20
-c max_replication_slots=20
-c hot_standby_feedback=on
depends_on:
- postgres_primary

Expand Down
Loading