parallel_tests with knapsack_pro on single CI machine
This tip is only relevant to you if you cannot use multiple parallel CI nodes on your CI provider. In such case, you can run your tests on a single CI machine with knapsack_pro
Queue Mode in order to auto balance execution of tests and thanks to this better utilize CI machine resources.
You can run knapsack_pro
with parallel_tests gem to run multiple concurrent knapsack_pro
commands on single CI node.
Create in your project directory an executable file bin/parallel_tests_knapsack_pro_single_machine
:
#!/bin/bash
# bin/parallel_tests_knapsack_pro_single_machine
export KNAPSACK_PRO_CI_NODE_TOTAL=$PARALLEL_TESTS_CONCURRENCY
if [ "$TEST_ENV_NUMBER" == "" ]; then
export KNAPSACK_PRO_CI_NODE_INDEX=0
else
export KNAPSACK_PRO_CI_NODE_INDEX=$(( $TEST_ENV_NUMBER - 1 ))
fi
echo KNAPSACK_PRO_CI_NODE_TOTAL=$KNAPSACK_PRO_CI_NODE_TOTAL KNAPSACK_PRO_CI_NODE_INDEX=$KNAPSACK_PRO_CI_NODE_INDEX PARALLEL_TESTS_CONCURRENCY=$PARALLEL_TESTS_CONCURRENCY
bundle exec rake knapsack_pro:queue:rspec
Then you need another script bin/parallel_tests_knapsack_pro_single_machine_run
to run above script with parallel_tests
:
#!/bin/bash
# bin/parallel_tests_knapsack_pro_single_machine_run
export PARALLEL_TESTS_CONCURRENCY=2;
RAILS_ENV=test \
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=xxx \
KNAPSACK_PRO_REPOSITORY_ADAPTER=git \
KNAPSACK_PRO_PROJECT_DIR=/home/user/rails-app-repo \
PARALLEL_TESTS_CONCURRENCY=$PARALLEL_TESTS_CONCURRENCY \
bundle exec parallel_test -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests_knapsack_pro_single_machine'
Now you can run bin/parallel_tests_knapsack_pro_single_machine_run
and it will execute 2 parallel processes with parallel_tests
. Each process will run knapsack_pro
Queue Mode to autobalance test files distribution across the processes.
See also
See also tips on how to do it on many parallel CI nodes where each node starts many parallel_tests processes.