test_synapse_port_db.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env bash
  2. #
  3. # Test script for 'synapse_port_db'.
  4. # - configures synapse and a postgres server.
  5. # - runs the port script on a prepopulated test sqlite db
  6. # - also runs it against an new sqlite db
  7. #
  8. # Expects Synapse to have been already installed with `poetry install --extras postgres`.
  9. # Expects `poetry` to be available on the `PATH`.
  10. set -xe
  11. cd "$(dirname "$0")/../.."
  12. echo "--- Generate the signing key"
  13. # Generate the server's signing key.
  14. poetry run synapse_homeserver --generate-keys -c .ci/sqlite-config.yaml
  15. echo "--- Prepare test database"
  16. # Make sure the SQLite3 database is using the latest schema and has no pending background update.
  17. poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
  18. # Create the PostgreSQL database.
  19. poetry run .ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
  20. echo "+++ Run synapse_port_db against test database"
  21. # TODO: this invocation of synapse_port_db (and others below) used to be prepended with `coverage run`,
  22. # but coverage seems unable to find the entrypoints installed by `pip install -e .`.
  23. poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
  24. # We should be able to run twice against the same database.
  25. echo "+++ Run synapse_port_db a second time"
  26. poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
  27. #####
  28. # Now do the same again, on an empty database.
  29. echo "--- Prepare empty SQLite database"
  30. # we do this by deleting the sqlite db, and then doing the same again.
  31. rm .ci/test_db.db
  32. poetry run update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
  33. # re-create the PostgreSQL database.
  34. poetry run .ci/scripts/postgres_exec.py \
  35. "DROP DATABASE synapse" \
  36. "CREATE DATABASE synapse"
  37. echo "+++ Run synapse_port_db against empty database"
  38. poetry run synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml