From c66e0d68a43543ab253972068475794f2e1e3991 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 15:38:02 +0100 Subject: [PATCH 1/6] Suggest using docker when testing against postgres --- docs/development/contributing_guide.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/development/contributing_guide.md b/docs/development/contributing_guide.md index d356c72bf780..fbe122490993 100644 --- a/docs/development/contributing_guide.md +++ b/docs/development/contributing_guide.md @@ -206,7 +206,24 @@ This means that we need to run our unit tests against PostgreSQL too. Our CI doe this automatically for pull requests and release candidates, but it's sometimes useful to reproduce this locally. -To do so, [configure Postgres](../postgres.md) and run `trial` with the +#### Using Docker + +The easiest way to do so is to run Postgres via a docker container. In one +terminal: + +```shell +docker run --rm -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_USER=postgres -e POSTGRES_DB=postgress -p 5432:5432 postgres:14 +``` + +Then in a second terminal, invoke `trial`: + +```shell +`SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests +```` + +#### Using an existing Postgres installation + +If you have postgres already installed on your system, you can run `trial` with the following environment variables matching your configuration: - `SYNAPSE_POSTGRES` to anything nonempty @@ -229,8 +246,8 @@ You don't need to specify the host, user, port or password if your Postgres server is set to authenticate you over the UNIX socket (i.e. if the `psql` command works without further arguments). -Your Postgres account needs to be able to create databases. - +Your Postgres account needs to be able to create databases; see the postgres +docs for [`ALTER ROLE`](https://www.postgresql.org/docs/current/sql-alterrole.html). ## Run the integration tests ([Sytest](https://github.com/matrix-org/sytest)). From 1b06ffd0c7c14d52d742640d35d2e4966c92e3d3 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 15:53:32 +0100 Subject: [PATCH 2/6] Changelog --- changelog.d/12765.doc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12765.doc diff --git a/changelog.d/12765.doc b/changelog.d/12765.doc new file mode 100644 index 000000000000..277b037d6b03 --- /dev/null +++ b/changelog.d/12765.doc @@ -0,0 +1 @@ +Recommend using docker to run tests against postgres. From c49d0a402c5cb1c515f485ef76c78e5faec4fc4f Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 17:59:34 +0100 Subject: [PATCH 3/6] Stray backtick Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --- docs/development/contributing_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/contributing_guide.md b/docs/development/contributing_guide.md index fbe122490993..3803518188f4 100644 --- a/docs/development/contributing_guide.md +++ b/docs/development/contributing_guide.md @@ -218,7 +218,7 @@ docker run --rm -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_USER=postgres Then in a second terminal, invoke `trial`: ```shell -`SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests +SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests ```` #### Using an existing Postgres installation From dac2fb80a6056cbfeaf45fcda144d96aea3a70e7 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 18:03:18 +0100 Subject: [PATCH 4/6] Example error message for duplicate postgreses --- docs/development/contributing_guide.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/development/contributing_guide.md b/docs/development/contributing_guide.md index 3803518188f4..cf6d43d787a0 100644 --- a/docs/development/contributing_guide.md +++ b/docs/development/contributing_guide.md @@ -215,7 +215,15 @@ terminal: docker run --rm -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_USER=postgres -e POSTGRES_DB=postgress -p 5432:5432 postgres:14 ``` -Then in a second terminal, invoke `trial`: +If you see an error like + +``` +docker: Error response from daemon: driver failed programming external connectivity on endpoint nice_ride (b57bbe2e251b70015518d00c9981e8cb8346b5c785250341a6c53e3c899875f1): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use. +``` + +then something is already bound to port 5432. You're probably already running postgres locally. + +Once you have a postgresThen in a second terminal, invoke `trial`: ```shell SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests From a4604ea5ebfada2b4677e205bfb0db0ad176ebf6 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 18:04:17 +0100 Subject: [PATCH 5/6] Fix fragmented sentence --- docs/development/contributing_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/contributing_guide.md b/docs/development/contributing_guide.md index cf6d43d787a0..eda7f40ff41f 100644 --- a/docs/development/contributing_guide.md +++ b/docs/development/contributing_guide.md @@ -223,7 +223,7 @@ docker: Error response from daemon: driver failed programming external connectiv then something is already bound to port 5432. You're probably already running postgres locally. -Once you have a postgresThen in a second terminal, invoke `trial`: +Once you have a postgres server runing, invoke `trial` in a second terminal: ```shell SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests From ccbae86a69993150ceefb1b9d727b8b983eb7084 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 17 May 2022 18:41:17 +0100 Subject: [PATCH 6/6] typofix, thanks Sean Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --- docs/development/contributing_guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/development/contributing_guide.md b/docs/development/contributing_guide.md index eda7f40ff41f..f55a1fbb9002 100644 --- a/docs/development/contributing_guide.md +++ b/docs/development/contributing_guide.md @@ -223,7 +223,7 @@ docker: Error response from daemon: driver failed programming external connectiv then something is already bound to port 5432. You're probably already running postgres locally. -Once you have a postgres server runing, invoke `trial` in a second terminal: +Once you have a postgres server running, invoke `trial` in a second terminal: ```shell SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_HOST=127.0.0.1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_POSTGRES_PASSWORD=mysecretpassword poetry run trial tests