Skip to content

Instantly share code, notes, and snippets.

@duykhoa
Last active October 20, 2015 09:21
Show Gist options
  • Save duykhoa/27b15ba4620d1b19474e to your computer and use it in GitHub Desktop.
Save duykhoa/27b15ba4620d1b19474e to your computer and use it in GitHub Desktop.
script to setup and run parallel test
function setupdb {
# Remove it, Just worked for me.
for I in {1..8}
do
echo " Setup db $I "
TEST_ENV_NUMBER=$I RAILS_ENV=crm_test rake db:drop
TEST_ENV_NUMBER=$I RAILS_ENV=crm_test rake db:create
TEST_ENV_NUMBER=$I RAILS_ENV=test rake crm:setup
TEST_ENV_NUMBER=$I RAILS_ENV=test rake crm:seed
done
export PARALLEL_TEST_PROCESSORS=8 # 8 threads
# prepare DB
rake parallel:drop
rake parallel:create
rake parallel:prepare
}
function execute {
echo 'Make sure that you have config your database.yml with crm_test & test db with'
echo
echo ' test:'
echo ' database_name: spanif_pg_test<%= ENV['TEST_ENV_NUMBER'] %>'
echo
echo ' crm_test:'
echo ' database_name: crm_test<%= ENV['TEST_ENV_NUMBER'] %>'
echo
read -p ' Did you want setup crm db and test db in parallel test mode? Remember there are multiple databases (y/n)? ' CONFIRM
if [ $CONFIRM == 'Y' ] || [ $CONFIRM == 'y' ]; then
setupdb
else
echo ' Skip setting db, now try to run the specs in parallel mode '
fi
echo ' Start running test'
DISABLE_SPRING=1 rake parallel:spec # spring doesn't work with parallel_test
}
execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment