2021-03-25 12:53:54 -04:00
|
|
|
#!/usr/bin/env bash
|
2019-10-28 13:45:32 -04:00
|
|
|
#
|
2021-05-10 08:02:55 -04:00
|
|
|
# Test script for 'synapse_port_db'.
|
|
|
|
# - sets up synapse and deps
|
|
|
|
# - runs the port script on a prepopulated test sqlite db
|
|
|
|
# - also runs it against an new sqlite db
|
|
|
|
|
2019-10-28 13:45:32 -04:00
|
|
|
|
|
|
|
set -xe
|
2021-10-22 18:07:23 -04:00
|
|
|
cd "$(dirname "$0")/../.."
|
2019-10-28 13:45:32 -04:00
|
|
|
|
2019-10-29 11:39:44 -04:00
|
|
|
echo "--- Install dependencies"
|
2019-10-28 13:45:32 -04:00
|
|
|
|
|
|
|
# Install dependencies for this test.
|
|
|
|
pip install psycopg2 coverage coverage-enable-subprocess
|
|
|
|
|
|
|
|
# Install Synapse itself. This won't update any libraries.
|
|
|
|
pip install -e .
|
|
|
|
|
2019-10-29 11:39:44 -04:00
|
|
|
echo "--- Generate the signing key"
|
|
|
|
|
|
|
|
# Generate the server's signing key.
|
2021-08-11 15:19:56 -04:00
|
|
|
python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml
|
2019-10-29 11:39:44 -04:00
|
|
|
|
2021-05-10 08:02:55 -04:00
|
|
|
echo "--- Prepare test database"
|
2019-10-29 11:39:44 -04:00
|
|
|
|
2019-10-28 13:45:32 -04:00
|
|
|
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
|
2022-03-02 08:00:16 -05:00
|
|
|
update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
|
2019-10-28 13:45:32 -04:00
|
|
|
|
|
|
|
# Create the PostgreSQL database.
|
2021-08-11 15:19:56 -04:00
|
|
|
.ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
|
2021-05-10 08:02:55 -04:00
|
|
|
|
|
|
|
echo "+++ Run synapse_port_db against test database"
|
2022-03-02 08:00:16 -05:00
|
|
|
# TODO: this invocation of synapse_port_db (and others below) used to be prepended with `coverage run`,
|
|
|
|
# but coverage seems unable to find the entrypoints installed by `pip install -e .`.
|
|
|
|
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
|
2021-05-10 08:02:55 -04:00
|
|
|
|
2021-05-24 09:03:00 -04:00
|
|
|
# We should be able to run twice against the same database.
|
|
|
|
echo "+++ Run synapse_port_db a second time"
|
2022-03-02 08:00:16 -05:00
|
|
|
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
|
2021-05-24 09:03:00 -04:00
|
|
|
|
2021-05-10 08:02:55 -04:00
|
|
|
#####
|
|
|
|
|
|
|
|
# Now do the same again, on an empty database.
|
|
|
|
|
|
|
|
echo "--- Prepare empty SQLite database"
|
|
|
|
|
|
|
|
# we do this by deleting the sqlite db, and then doing the same again.
|
2021-08-11 15:19:56 -04:00
|
|
|
rm .ci/test_db.db
|
2021-05-10 08:02:55 -04:00
|
|
|
|
2022-03-02 08:00:16 -05:00
|
|
|
update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
|
2019-10-29 11:39:44 -04:00
|
|
|
|
2021-05-10 08:02:55 -04:00
|
|
|
# re-create the PostgreSQL database.
|
2021-08-11 15:19:56 -04:00
|
|
|
.ci/scripts/postgres_exec.py \
|
2021-05-10 08:02:55 -04:00
|
|
|
"DROP DATABASE synapse" \
|
|
|
|
"CREATE DATABASE synapse"
|
2019-10-28 13:45:32 -04:00
|
|
|
|
2021-05-10 08:02:55 -04:00
|
|
|
echo "+++ Run synapse_port_db against empty database"
|
2022-03-02 08:00:16 -05:00
|
|
|
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
|