test_synapse_port_db.sh 1.9 KB

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