Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run test-runner setup steps in parallel #4100

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
12 changes: 11 additions & 1 deletion 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,10 +275,14 @@ function setup_db(){
fi
}

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_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
15 changes: 8 additions & 7 deletions tools/wait_for_healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ if [ "$#" -ne 1 ]; then
fi
CONTAINER="$1"

CMD=$($DOCKER inspect "$CONTAINER" --format '{{println (index .Config.Healthcheck.Test 1) }}')

# Default timeout is 1 minute
TIMEOUT="${TIMEOUT:-60}"

# Gets a health check of a container
# Usage example:
# health_status "$CONTAINER"
function health_status
{
$DOCKER inspect --format '{{json .State.'${DOCKER_HEALTH}'.Status }}' "$1"
# Directly run the command
# We could run "docker inspect" to get the healthcheck status from Docker,
# but it often takes health-interval seconds to return Healthy (i.e. 30 seconds by default)
function run_health_check_command {
$DOCKER exec "$CONTAINER" sh -c "$CMD"
}

for i in $(seq 0 ${TIMEOUT}); do
if [ $(health_status "$CONTAINER")"" = "\"healthy\"" ]; then
if run_health_check_command ; then
echo -e "\nWaiting is done after $i seconds"
exit 0
fi
Expand Down