Skip to content

Commit

Permalink
Setting up test env in parallel
Browse files Browse the repository at this point in the history
New tools/parallel.sh script
Sets up databases and build big_tests/releases in parallel
  • Loading branch information
arcusfelis committed Aug 14, 2023
1 parent 41dcf3b commit 212a65c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
57 changes: 57 additions & 0 deletions tools/parallel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Include the file to add helpers for parallel tasks.
# Example:
# source tools/common-vars.sh
# source tools/parallel.sh

PARALLEL_ENABLED=${PARALLEL_ENABLED-true}

# Add prefix to all lines of the output
function exec_with_prefix
{
NAME="$1"
shift
if [ "$NAME" = "false" ]; then
# no prefix
$@
else
# Apply a separate sed filter on stderr
$@ \
2> >($SED -e "s/^/$NAME stderr:\t/;" >&2) \
| $SED -e "s/^/$NAME:\t/;"
fi
echo "DONE $NAME"
}

function cleanup_parallel
{
trap "" INT TERM ERR
echo "Cleanup parallel tasks $1"
kill 0
}

function init_parallel
{
if [ "$PARALLEL_ENABLED" = "true" ]; then
X=$$
# Kill background jobs if the user clicks CTRL-C
trap "cleanup_parallel $1" INT TERM ERR
fi
}

function parallel
{
if [ "$PARALLEL_ENABLED" = "true" ]; then
exec_with_prefix $@ &
else
shift # ignore an argument with a prefix
$@
fi
}

function wait_for_parallel
{
if [ "$PARALLEL_ENABLED" = "true" ]; then
wait
echo "Done $1"
fi
}
15 changes: 9 additions & 6 deletions tools/setup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

set -e

# Switch to the repository directory
cd "$( dirname "${BASH_SOURCE[0]}" )/.."

source tools/common-vars.sh
source tools/parallel.sh
source tools/db-versions.sh

MIM_PRIV_DIR=${BASE}/priv
Expand All @@ -19,6 +23,8 @@ PGSQL_ODBC_CERT_DIR=~/.postgresql

SSLDIR=${TOOLS}/ssl

PARALLEL_ENABLED=${PARALLEL_ENABLED-true}

function setup_db(){
db=${1:-none}
echo "Setting up db: $db"
Expand Down Expand Up @@ -269,17 +275,14 @@ function setup_db(){
fi
}

# Kill background jobs if the user clicks CTRL-C
trap "exit" INT TERM ERR
trap "kill 0" EXIT
init_parallel setup_db

# The DB env var may contain single value "mysql"
# or list of values separated with a space "elasticsearch cassandra"
# in case of list of values all listed database will be set up (or at least tried)

for db in ${DB}; do
setup_db $db &
parallel "$db" setup_db "$db"
done

wait
echo "setup_db done"
wait_for_parallel setup_db
1 change: 1 addition & 0 deletions tools/test-runner-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ _run_all_tests() {
--skip-start-nodes \
--skip-stop-nodes \
--skip-setup-db \
--no-parallel \
--tls-dist \
--verbose \
--help \
Expand Down
26 changes: 22 additions & 4 deletions tools/test-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# Fail on errors
set -e

# Switch to the repository directory
cd "$( dirname "${BASH_SOURCE[0]}" )/.."

source tools/common-vars.sh
source tools/parallel.sh

USAGE=$(cat <<-END
This script runs small and big tests for MongooseIM
Expand All @@ -31,6 +37,7 @@ Options:
--skip-start-nodes -- do not start nodes before big tests
--skip-stop-nodes -- do not stop nodes after big tests
--skip-setup-db -- do not start any databases, the same as "--db --" option
--no-parallel -- run most commands in sequence
--tls-dist -- enable encryption between nodes in big tests
--verbose -- print script output
--colors -- force colors in help and examples commands
Expand Down Expand Up @@ -295,6 +302,7 @@ BUILD_MIM=true
START_NODES=true
STOP_NODES=true
TLS_DIST=false
PARALLEL_ENABLED=true

SELECTED_TESTS=()
STOP_SCRIPT=false
Expand Down Expand Up @@ -418,6 +426,11 @@ case $key in
COVER_ENABLED=false
;;

--no-parallel)
shift # past argument
PARALLEL_ENABLED=false
;;

--skip-preset)
shift # past argument
# Disable preset application
Expand Down Expand Up @@ -641,12 +654,17 @@ echo " START_NODES=$START_NODES"
echo " STOP_NODES=$STOP_NODES"
echo ""

./tools/build-releases.sh

./tools/build-tests.sh
init_parallel test_runner

parallel build-mim ./tools/build-releases.sh

parallel build-tests ./tools/build-tests.sh

parallel make-spec ./tools/test_runner/selected-tests-to-test-spec.sh "${SELECTED_TESTS[@]}"

./tools/test_runner/selected-tests-to-test-spec.sh "${SELECTED_TESTS[@]}"
parallel false ./tools/setup-db.sh

./tools/setup-db.sh
wait_for_parallel test_runner

./tools/test.sh

0 comments on commit 212a65c

Please sign in to comment.