Skip to content

Instantly share code, notes, and snippets.

@Daanvm
Last active October 10, 2020 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daanvm/1164f04b4d5b706628f1c28ecde90717 to your computer and use it in GitHub Desktop.
Save Daanvm/1164f04b4d5b706628f1c28ecde90717 to your computer and use it in GitHub Desktop.
This script sets up multiple, identical test databases that can be used by integration tests that run in parallel.
#!/bin/bash
#
# This script sets up multiple, identical test databases that can be used by
# integration tests that run in parallel.
set -euo pipefail
# Create one test database named `mollie_test_db_1`. Yes, our parallel test
# suits start counting from 1. Don't ask.
# [...]
# Create a dump of the first database
mysqldump --host=localhost --user=root "mollie_test_db_1" > "/tmp/mollie_test_db_dump.sql"
# Import it into all the other databases. Perform the process in the background
# (with the `&` at the end) so all the imports will happen async. Store the PIDs
# so we can later wait for these processes to be completed.
pids_to_wait_for=()
for i in $(seq 2 "${nr_of_databases}"); do
mysql --host=localhost --user=root "mollie_test_db_${i}" < "/tmp/mollie_test_db_dump.sql" &
pids_to_wait_for[${i}]=$!
done
# Wait for the MySQL imports to be completed.
for pid in ${pids_to_wait_for[*]}; do
wait $pid
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment