test_synapse_port_db.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. scripts/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. coverage run scripts/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. coverage run scripts/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. scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
  33. # re-create the PostgreSQL database.
  34. .ci/scripts/postgres_exec.py \
  35. "DROP DATABASE synapse" \
  36. "CREATE DATABASE synapse"
  37. echo "+++ Run synapse_port_db against empty database"
  38. coverage run scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml