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

Add a way to run tests in PostgreSQL in Docker #3699

Merged
merged 9 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 24 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,30 @@ use github's pull request workflow to review the contribution, and either ask
you to make any refinements needed or merge it and make them ourselves. The
changes will then land on master when we next do a release.

We use `Jenkins <http://matrix.org/jenkins>`_ and
`Travis <https://travis-ci.org/matrix-org/synapse>`_ for continuous
integration. All pull requests to synapse get automatically tested by Travis;
the Jenkins builds require an adminstrator to start them. If your change
breaks the build, this will be shown in github, so please keep an eye on the
pull request for feedback.
We use `Jenkins <http://matrix.org/jenkins>`_, `CircleCI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we don't use jenkins any more...)

<https://circleci.com/gh/matrix-org>`_ and `Travis
<https://travis-ci.org/matrix-org/synapse>`_ for continuous integration. All
pull requests to synapse get automatically tested by Travis and CircleCI; the
Jenkins builds require an adminstrator to start them. If your change breaks the
build, this will be shown in GitHub, so please keep an eye on the pull request
for feedback.

To run unit tests, you can use:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest "To run unit tests on a development environment ..." to distinguish from the previous paragraph about CI and PRs


- ``tox -e py27`` (requires tox to be installed by ``pip install tox``) for
SQLite-backed Synapse on Python 2.7.
- ``tox -e py35`` for SQLite-backed Synapse on Python 3.5.
- ``tox -e py36`` for SQLite-backed Synapse on Python 3.6.
- ``tox -e py27-postgres`` for PostgreSQL-backed Synapse on Python 2.7
(requires a running local PostgreSQL with access to create databases).
- ``./test_postgresql.sh`` for PostgreSQL-backed Synapse on Python 2.7
(requires Docker). Entirely self-contained, recommended if you don't want to
set up PostgreSQL yourself.

Docker images are available for running the integration tests (SyTest) locally,
see the `documentation in the SyTest repo
<https://github.com/matrix-org/sytest/blob/develop/docker/README.md>`_ for more
information.

Code style
~~~~~~~~~~
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile-pgtests
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM matrixdotorg/sytest:latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we stick the Dockerfile in the docker directory to avoid cluttering the top-level more than necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it also have a comment saying what it does?


RUN apt-get -qq install -y python python-dev python-pip

RUN pip install tox

ADD docker_run_pg_tests.sh /pg_tests.sh
ENTRYPOINT /pg_tests.sh
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ exclude jenkins*.sh
exclude jenkins*
exclude Dockerfile
exclude .dockerignore
exclude Dockerfile-pgtests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably redundant if the dockerfile is in the docker dir?

exclude docker_run_pg_tests.sh
exclude test_postgresql.sh
recursive-exclude jenkins *.sh

include pyproject.toml
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/3699.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Unit tests can now be run under PostgreSQL in Docker using
``test_postgresql.sh``.
10 changes: 10 additions & 0 deletions docker_run_pg_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export PGDATA=/var/lib/postgresql/data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do with a shebang line and a comment saying what it does?

and a set -e maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it go in a subdir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

export PGUSER=postgres

# Initialise the database files and start the database
su -c '/usr/lib/postgresql/9.6/bin/initdb -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

cd /src
export TRIAL_FLAGS="-j 4"
tox -e py27-postgres
3 changes: 3 additions & 0 deletions test_postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#!/bin/bash is conventional for shell scripts.

Does it need a set -e so that it doesn't plough on with the run if the build fails?

docker build . -f Dockerfile-pgtests -t synapsepgtests
docker run --rm -it -v $(pwd)\:/src synapsepgtests