Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Update postgresql testing script #10906

Merged
merged 11 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelog.d/10906.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update development testing script `test_postgresql.sh` to use a support Python version and make re-runs quicker.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 11 additions & 2 deletions docker/Dockerfile-pgtests
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Use the Sytest image that comes with a lot of the build dependencies
# pre-installed
FROM matrixdotorg/sytest:latest
FROM matrixdotorg/sytest:bionic
reivilibre marked this conversation as resolved.
Show resolved Hide resolved

# The Sytest image doesn't come with python, so install that
RUN apt-get update && apt-get -qq install -y python3 python3-dev python3-pip

# We need tox to run the tests in run_pg_tests.sh
RUN python3 -m pip install tox

# Initialise the db
RUN su -c '/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/data -E "UTF-8" --lc-collate="en_US.UTF-8" --lc-ctype="en_US.UTF-8" --username=postgres' postgres
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

# Create a volume for tox's workdir (so we don't have to fetch dependencies from PyPI every run)
VOLUME /tox

ADD run_pg_tests.sh /pg_tests.sh
ENTRYPOINT /pg_tests.sh

# Use the "exec form" of ENTRYPOINT (https://docs.docker.com/engine/reference/builder/#entrypoint)
# so that we can `docker run` this container and pass arguments to pg_tests.sh
ENTRYPOINT ["/pg_tests.sh"]
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 3 additions & 4 deletions docker/run_pg_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ set -e
# Set PGUSER so Synapse's tests know what user to connect to the database with
export PGUSER=postgres

# Initialise & start the database
su -c '/usr/lib/postgresql/9.6/bin/initdb -D /var/lib/postgresql/data -E "UTF-8" --lc-collate="en_US.UTF-8" --lc-ctype="en_US.UTF-8" --username=postgres' postgres
su -c '/usr/lib/postgresql/9.6/bin/pg_ctl -w -D /var/lib/postgresql/data start' postgres
# Start the database
su -c '/usr/lib/postgresql/10/bin/pg_ctl -w -D /var/lib/postgresql/data start' postgres

# Run the tests
cd /src
export TRIAL_FLAGS="-j 4"
tox --workdir=/tmp -e py35-postgres
tox --workdir=/tox -e py36-postgres "$@"
22 changes: 22 additions & 0 deletions scripts-dev/test_postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This script builds the Docker image to run the PostgreSQL tests, and then runs
# the tests. It uses a dedicated tox environment so that we don't have to
# rebuild it each time.

# Command line arguments to this script are forwarded to "tox" and then to "trial".

set -e

# Build, and tag
docker build docker/ -f docker/Dockerfile-pgtests -t synapsepgtests

# Create a place to persist tox's environment so reruns are faster.
# NB: I'm using a separate docker volume here, because you may have already run
# "tox -e py36-postgres" on your system. You might not be using the distro used
# in Dockerfile-pgtests, and so might be using a different CPython build! I don't
# want there to be any accidental clashes
docker volume create synapse-pg-test-tox
reivilibre marked this conversation as resolved.
Show resolved Hide resolved

# Run, mounting the current directory into /src
docker run --rm -it -v "$(pwd):/src" -v synapse-pg-test-tox:/tox synapsepgtests "$@"
12 changes: 0 additions & 12 deletions test_postgresql.sh

This file was deleted.