diff --git a/.ci/scripts/calculate_jobs.py b/.ci/scripts/calculate_jobs.py index 1ddea715b0..67b747195a 100755 --- a/.ci/scripts/calculate_jobs.py +++ b/.ci/scripts/calculate_jobs.py @@ -81,6 +81,14 @@ trial_postgres_tests = [ "postgres-version": "17", "extras": "all", }, + # Postgres through the native Rust driver rather than psycopg2. + { + "python-version": "3.14", + "database": "postgres", + "postgres-version": "17", + "extras": "all", + "driver": "rust", + }, ] # Ensure that Synapse passes unit tests even with no extra dependencies installed. diff --git a/.github/workflows/complement_tests.yml b/.github/workflows/complement_tests.yml index cb43c1a106..f6b14a12b9 100644 --- a/.github/workflows/complement_tests.yml +++ b/.github/workflows/complement_tests.yml @@ -37,6 +37,10 @@ jobs: - arrangement: workers database: Postgres + - arrangement: monolith + database: Postgres + driver: rust + steps: - name: Checkout synapse codebase uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -114,6 +118,7 @@ jobs: env: POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }} + RUST_DRIVER: ${{ (matrix.driver == 'rust') && 1 || '' }} - name: Formatted sanity check Complement test logs # Always run this step if we attempted to run the Complement tests. @@ -146,6 +151,7 @@ jobs: env: POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }} + RUST_DRIVER: ${{ (matrix.driver == 'rust') && 1 || '' }} TEST_ONLY_IGNORE_POETRY_LOCKFILE: ${{ inputs.use_latest_deps && 1 || '' }} TEST_ONLY_SKIP_DEP_HASH_VERIFICATION: ${{ inputs.use_twisted_trunk && 1 || '' }} @@ -183,6 +189,7 @@ jobs: env: POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }} + RUST_DRIVER: ${{ (matrix.driver == 'rust') && 1 || '' }} TEST_ONLY_IGNORE_POETRY_LOCKFILE: ${{ inputs.use_latest_deps && 1 || '' }} TEST_ONLY_SKIP_DEP_HASH_VERIFICATION: ${{ inputs.use_twisted_trunk && 1 || '' }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 14a4fcdc4e..a4daef4fbd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -449,6 +449,7 @@ jobs: SYNAPSE_POSTGRES_HOST: /var/run/postgresql SYNAPSE_POSTGRES_USER: postgres SYNAPSE_POSTGRES_PASSWORD: postgres + SYNAPSE_TEST_RUST_DRIVER: ${{ matrix.job.driver == 'rust' || '' }} - name: Dump logs # Logs are most useful when the command fails, always include them. if: ${{ always() }} @@ -725,6 +726,21 @@ jobs: - linting-done - changes + # The native Postgres driver's tests run against a live server and are + # skipped without one. + services: + postgres: + image: postgres:17 + env: + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -735,6 +751,8 @@ jobs: - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 - run: cargo test + env: + SYNAPSE_TEST_POSTGRES_DSN: host=localhost user=postgres password=postgres dbname=postgres # We want to ensure that the cargo benchmarks still compile, which requires a # nightly compiler. diff --git a/docker/complement/conf/start_for_complement.sh b/docker/complement/conf/start_for_complement.sh index e0d30abed3..e0cd275ff3 100755 --- a/docker/complement/conf/start_for_complement.sh +++ b/docker/complement/conf/start_for_complement.sh @@ -6,7 +6,7 @@ set -e echo "Complement Synapse launcher" echo " Args: $*" -echo " Env: SYNAPSE_COMPLEMENT_DATABASE=$SYNAPSE_COMPLEMENT_DATABASE SYNAPSE_COMPLEMENT_USE_WORKERS=$SYNAPSE_COMPLEMENT_USE_WORKERS SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=$SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR" +echo " Env: SYNAPSE_COMPLEMENT_DATABASE=$SYNAPSE_COMPLEMENT_DATABASE SYNAPSE_COMPLEMENT_USE_WORKERS=$SYNAPSE_COMPLEMENT_USE_WORKERS SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=$SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR SYNAPSE_USE_RUST_DRIVER=$SYNAPSE_USE_RUST_DRIVER" function log { d=$(printf '%(%Y-%m-%d %H:%M:%S)T,%.3s\n' ${EPOCHREALTIME/./ }) diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index d8e553f446..ccbbc7b924 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -358,6 +358,12 @@ main() { export PASS_SYNAPSE_COMPLEMENT_USE_ASYNCIO_REACTOR=true fi + if [[ -n "$RUST_DRIVER" ]]; then + # Talk to Postgres through the native Rust driver (`use_rust_driver`) + # instead of psycopg2. Only meaningful with POSTGRES=1. + export PASS_SYNAPSE_USE_RUST_DRIVER=true + fi + if [[ -n "$UNIX_SOCKETS" ]]; then # Enable full on Unix socket mode for Synapse, Redis and Postgresql export PASS_SYNAPSE_USE_UNIX_SOCKET=1