# sed here to quote export CASSANDRA_PORTS=7199 9042 => export CASSANDRA_PORTS="7199 9042"
evalecho"export $env_var"| sed 's/=/="/;s/$/"/'
done
@ -261,9 +264,23 @@ run++(){
}
run(){
if[ -n "${FAIL:-}"];then
run_fail "$FAIL""$@"
else
run++
echo"$@"
"$@"
fi
}
run_output(){
localexpected_output="$1"
shift
run++
echo"$@"
"$@"
set +e
check_output "$expected_output""$@"
set -e
}
run_fail(){
@ -283,9 +300,9 @@ run_grep(){
shift
run++
echo"$@ | tee /dev/stderr | egrep '$egrep_pattern'"
set +eo pipefail
set +o pipefail
"$@"| tee /dev/stderr | egrep -q "$egrep_pattern"
set -eo pipefail
set -o pipefail
}
run_test_versions(){
@ -296,6 +313,10 @@ run_test_versions(){
for version in $test_versions;do
run_count=0
eval"$test_func""$version"
if[$run_count -eq 0];then
echo"NO TEST RUNS DETECTED!"
exit1
fi
lettotal_run_count+=$run_count
done
@ -347,15 +368,10 @@ startupwait(){
}
when_ports_available(){
localmax_secs="$1"
localhost="$2"
localmax_secs="${1:-}"
localhost="${2:-}"
localports="${@:3}"
localretry_interval=1
if ! which nc &>/dev/null;then
# Don't run in docker containers
echo"WARNING: nc command not found in \$PATH, cannot check port availability, skipping port checks, tests may fail due to race conditions on service availability"
return0
fi
if[ -z "$max_secs"];then
echo'when_ports_available: max_secs $1 not set'
exit1
@ -408,17 +424,88 @@ when_ports_available(){
timestamp "host '$host' port$plural '$ports' available after $SECONDS secs"
else
timestamp "host '$host' port$plural '$ports' still not available after '$max_secs' secs, giving up waiting"
return1
fi
else
echo"'nc' command not found, sleeping for '$max_secs' secs instead"
echo"WARNING: nc command not found in \$PATH, cannot check port availability, skipping port checks, tests may fail due to race conditions on service availability"
echo"sleeping for '$max_secs' secs instead"
sleep "$max_secs"
fi
}
# Do not use this on docker containers
# docker mapped ports still return connection succeeded even when the process mapped to them is no longer listening inside the container!
# must be the result of docker networking
when_ports_down(){
localmax_secs="${1:-}"
localhost="${2:-}"
localports="${@:3}"
localretry_interval=1
if[ -z "$max_secs"];then
echo'when_ports_down: max_secs $1 not set'
exit1
#elif ! egrep '^[[:digit:]]+$' <<< "$max_secs"; then
elif ! [["$max_secs"=~ ^[[:digit:]]+$ ]];then
echo'when_ports_down: invalid non-numeric first argument passed for max_secs'
exit1
elif[ -z "$host"];then
echo'when_ports_down: host $2 not set'
exit1
elif[ -z "$ports"];then
echo'when_ports_down: ports $3 not set'
exit1
else
for port in $ports;do
if ! [["$port"=~ ^[[:digit:]]+$ ]];then
echo"when_ports_down: invalid non-numeric port argument '$port'"
exit1
fi
done
fi
#local max_tries=$(($max_secs / $retry_interval))
# Linux nc doens't have -z switch like Mac OSX version
localnc_cmd="nc -vw $retry_interval$host <<< ''"
cmd=""
for x in $ports;do
cmd="$cmd ! $nc_cmd$x &>/dev/null && "
done
localcmd="${cmd% && }"
plural_str $ports
echo"waiting for up to $max_secs secs for port$plural '$ports' to go down, retrying at $retry_interval sec intervals"
echo"cmd: ${cmd// \&\>\/dev\/null}"
localdown=0
if which nc &>/dev/null;then
#for((i=1; i <= $max_tries; i++)); do
try_number=0
# special built-in that increments for script runtime, reset to zero exploit it here
SECONDS=0
# bash will interpolate from string for correct numeric comparison and safer to quote vars
timestamp "host '$host' port$plural '$ports' down after $SECONDS secs"
else
timestamp "host '$host' port$plural '$ports' still not down after '$max_secs' secs, giving up waiting"
return1
fi
else
echo"WARNING: nc command not found in \$PATH, cannot check for ports down, skipping port checks, tests may fail due to race conditions on service availability"
echo"sleeping for '$max_secs' secs instead"
sleep "$max_secs"
fi
}
when_url_content(){
localmax_secs="$1"
localurl="$2"
localexpected_regex="$3"
localmax_secs="${1:-}"
localurl="${2:-}"
localexpected_regex="${3:-}"
localargs="${@:4}"
localretry_interval=1
if[ -z "$max_secs"];then
@ -442,20 +529,27 @@ when_url_content(){
# special built-in that increments for script runtime, reset to zero exploit it here
SECONDS=0
# bash will interpolate from string for correct numeric comparison and safer to quote vars
timestamp "URL content still not available after '$max_secs' secs, giving up waiting"
return1
fi
sleep "$retry_interval"
done
if[$found -eq 1];then
timestamp "URL content found after $SECONDS secs"
else
timestamp "URL content still not available after '$max_secs' secs, giving up waiting"
echo"WARNING: curl command not found in \$PATH, cannot check url content, skipping content checks, tests may fail due to race conditions on service availability"