-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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