Skip to content

Commit

Permalink
src/test/osd/safe-to-destroy.sh: Add parallelism
Browse files Browse the repository at this point in the history
This patch is about adding some parallelism into this test.
Every "action" to test is spawn in a subshell with a custom testing env:
- a separate directory
- a different cluster id
- a different port

This way it is possible spawning several tests in parallel. The pids are
stored in bash arrays and the exit status are double-checked after the
run.

Regarding the exit code, the pass is reported as passed or failed.

This patch is saving 55 seconds.

Before: 1/1 Test ceph#135: safe-to-destroy.sh ...............   Passed  126.26 sec
After : 1/1 Test ceph#135: safe-to-destroy.sh ...............   Passed   71.47 sec
Signed-off-by: Erwan Velu <erwan@redhat.com>
  • Loading branch information
Erwan Velu committed Jun 15, 2018
1 parent b2c6c83 commit 0eb3e07
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions src/test/osd/safe-to-destroy.sh
Expand Up @@ -4,22 +4,70 @@ source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

set -e

function do_test() {
action=$1
# Each test have a separate directory
dir=$2_$action
# Let's define a port per test
port=$((7227 + $3))
CEPH_DISK_ARGS+=" --statedir=$dir"
CEPH_DISK_ARGS+=" --sysconfdir=$dir"

export CEPH_MON="127.0.0.1:$port"
export CEPH_ARGS
CEPH_ARGS+=" --fsid=$(uuidgen)"
CEPH_ARGS+=" --auth-supported=none"
CEPH_ARGS+=" --mon-host=$CEPH_MON"
setup $dir || exit 1
set -x
$action $dir || exit 1
set +x
teardown $dir || exit 1
exit 0
}


function run() {
local dir=$1
shift

export CEPH_MON="127.0.0.1:7227" # git grep '\<7227\>' : there must be only one
export CEPH_ARGS
CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
CEPH_ARGS+="--mon-host=$CEPH_MON "
set -e

local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
local actions=()
for func in $funcs ; do
setup $dir || return 1
$func $dir || return 1
teardown $dir || return 1
actions+=($func)
done

pids=()
# For every defined action,
# let's start the test in a subshell
# And save the pid in the 'pids' array
for action in ${actions[*]}; do
(do_test $action $dir ${#pids[*]}) &
pids+=($!)
done

failed=""
pos=0
# For every pid we have spawn
# let's check the exit code
# and save the name of the broken ones
for pid in ${pids[*]}; do
wait $pid
if [ $? -ne 0 ]; then
failed="$failed ${actions[$pos]}"
fi
pos=$(($pos + 1))
done

# If at least one test failed, let's return 1
if [ -n "$failed" ]; then
echo "Failed tests are $failed"
return 1
fi

return 0
}

function TEST_safe_to_destroy() {
Expand Down

0 comments on commit 0eb3e07

Please sign in to comment.