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
20 changes: 18 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: "0 6 * * 0"

jobs:
test:
test-core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and install extension
run: |
make
sudo make install
- name: Run tests
- name: Run core tests
run: |
docker compose up --abort-on-container-exit --exit-code-from test test

test-slow-suites:
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and install extension
run: |
make
sudo make install
- name: Run integration and performance suites
run: |
docker compose run --rm -e RUN_INTEGRATION=1 -e RUN_PERF=1 test make test-all
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,26 @@ CREATE EXTENSION pg_git;

## Testing

`make test` now runs a preflight (`test-preflight`) before executing SQL TAP tests. The preflight checks:
- PostgreSQL connectivity using `PGHOST`, `PGPORT`, `PGUSER`, `PGDATABASE`
- required extensions are enabled (`pgcrypto`, `pg_trgm`, `plpython3u`)
- `pg_prove` is installed and on `PATH`
Test suites are split by speed and external dependencies:

### Known-good test matrix
- `test-core` (default): deterministic SQL tests for local logic. **Expected runtime:** ~10-30 seconds in Docker on a modern laptop. **Prerequisites:** running PostgreSQL test database.
- `test-integration` (opt-in): HTTPS transport checks in `test/sql/https_fetch_test.sql`. **Expected runtime:** ~30-90 seconds depending on network/container startup. **Prerequisites:** set `RUN_INTEGRATION=1`; `plpython3u` available; outbound HTTPS/network available.
- `test-performance` (opt-in): GC performance regression checks in `test/sql/gc_performance_test.sql`. **Expected runtime:** ~1-5+ minutes depending on machine load. **Prerequisites:** set `RUN_PERF=1`; stable CPU/IO for consistent measurements.
- `test-all`: runs `test-core` and then conditionally runs integration/performance suites when their flags are enabled.

| Environment | Connection setup | Test command |
| --- | --- | --- |
| Local PostgreSQL | `export PGHOST=localhost PGPORT=5432 PGUSER=postgres PGDATABASE=postgres` | `make test` |
| Docker Compose (`db` service) | `PGHOST=db PGPORT=5432 PGUSER=postgres PGDATABASE=pg_git_dev` (already set in `docker-compose.yml`) | `docker-compose run --rm test` |
```bash
# Fast default suite (also what `make test` runs)
make test-core

# Explicitly include HTTPS/integration tests
RUN_INTEGRATION=1 make test-integration

If preflight fails, fix the reported prerequisite and re-run `make test`.
# Explicitly include performance tests
RUN_PERF=1 make test-performance

# Run everything (slow suites run only when flags are set)
RUN_INTEGRATION=1 RUN_PERF=1 make test-all
```

## Development
Using Docker:
Expand Down
83 changes: 41 additions & 42 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,55 @@ DATA = \
$(wildcard sql/schema/*.sql) \
$(wildcard sql/functions/*.sql)

# Authoritative test order lives in test/sql/manifest.txt.
TEST_MANIFEST := test/sql/manifest.txt
TESTS := $(shell sed -e '/^[[:space:]]*#/d' -e '/^[[:space:]]*$$/d' $(TEST_MANIFEST))
# Deterministic, fast SQL tests that run on every change.
CORE_TESTS := \
test/sql/init.sql \
test/sql/add_test.sql \
test/sql/branch_test.sql \
test/sql/commit_test.sql \
test/sql/diff_test.sql \
test/sql/merge_test.sql \
test/sql/remote_test.sql \
test/sql/advanced_test.sql \
test/sql/gc_test.sql \
test/sql/optimize_indexes_test.sql

# Slower/less deterministic suites are opt-in.
INTEGRATION_TESTS := \
test/sql/https_fetch_test.sql

PERFORMANCE_TESTS := \
test/sql/gc_performance_test.sql

# Backward-compatible aggregate for PGXS regress helpers.
TESTS := $(CORE_TESTS) $(INTEGRATION_TESTS) $(PERFORMANCE_TESTS)

# Derive the target names from the TESTS list to keep them in sync.
REGRESS := $(notdir $(basename $(TESTS)))
REGRESS_OPTS = --inputdir=test

include $(PGXS)

.PHONY: test test-preflight

test-preflight:
@command -v pg_prove >/dev/null 2>&1 || { \
echo "ERROR: pg_prove is not installed or not on PATH."; \
echo "Install it via your package manager (often in postgresql-test/perl-Test-Harness-TAP packages)."; \
exit 1; \
}
@$(PSQL) -c 'SELECT 1;' >/dev/null || { \
echo "ERROR: unable to connect to PostgreSQL using PGHOST=$(PGHOST) PGPORT=$(PGPORT) PGUSER=$(PGUSER) PGDATABASE=$(PGDATABASE)."; \
echo "Check credentials, host reachability, and that the database exists."; \
exit 1; \
}
@$(PSQL) -tA -c "SELECT string_agg(e, ', ') FROM (VALUES ('pgcrypto'),('pg_trgm'),('plpython3u')) AS req(e) WHERE NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = req.e);" | \
awk 'NF { printf "ERROR: missing required extensions: %s\n", $$0; print "Install with: CREATE EXTENSION <name>;"; exit 1 }'
@echo "Preflight checks passed for PGHOST=$(PGHOST) PGPORT=$(PGPORT) PGUSER=$(PGUSER) PGDATABASE=$(PGDATABASE)."

test: test-preflight
pg_prove -h $(PGHOST) -p $(PGPORT) -U $(PGUSER) -d $(PGDATABASE) $(TESTS)

.PHONY: test test-one test-one-verbose test-list
test:
pg_prove -d postgres $(TESTS)

# Focused rerun for a single SQL test file: make test-one TEST=test/sql/merge_test.sql
test-one:
@if [ -z "$(TEST)" ]; then \
echo "Usage: make test-one TEST=test/sql/<file>.sql"; \
exit 1; \
.PHONY: test test-core test-integration test-performance test-all

# Keep `make test` as fast default.
test: test-core

test-core:
pg_prove -d postgres $(CORE_TESTS)

test-integration:
@if [ "$(RUN_INTEGRATION)" != "1" ]; then \
echo "Skipping integration tests. Set RUN_INTEGRATION=1 to run them."; \
exit 0; \
fi
pg_prove -d postgres $(TEST)
pg_prove -d postgres $(INTEGRATION_TESTS)

# Verbose focused rerun for richer diagnostics
test-one-verbose:
@if [ -z "$(TEST)" ]; then \
echo "Usage: make test-one-verbose TEST=test/sql/<file>.sql"; \
exit 1; \
test-performance:
@if [ "$(RUN_PERF)" != "1" ]; then \
echo "Skipping performance tests. Set RUN_PERF=1 to run them."; \
exit 0; \
fi
pg_prove -v -d postgres $(TEST)
pg_prove -d postgres $(PERFORMANCE_TESTS)

# Print registered SQL test files in execution order
test-list:
@printf "%s\n" $(TESTS)
test-all: test-core test-integration test-performance
Loading