Reduce errexit modifications (#1785)

This is less error prone but requires some magic && ||.
This commit is contained in:
Andrew Gaul 2021-10-25 23:53:45 +09:00 committed by GitHub
parent 23fe6f4dee
commit ea3c21f270
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 25 deletions

View File

@ -103,25 +103,22 @@ fi
# This function execute the function parameters $1 times # This function execute the function parameters $1 times
# before giving up, with 1 second delays. # before giving up, with 1 second delays.
function retry { function retry {
set +o errexit
N=$1; shift; N=$1; shift;
status=0 rc=0
for i in $(seq $N); do for i in $(seq $N); do
echo "Trying: $*" echo "Trying: $*"
eval $@ eval $@ && rc=$? || rc=$?
status=$? if [ $rc == 0 ]; then
if [ $status == 0 ]; then
break break
fi fi
sleep 1 sleep 1
echo "Retrying: $*" echo "Retrying: $*"
done done
if [ $status != 0 ]; then if [ $rc != 0 ]; then
echo "timeout waiting for $*" echo "timeout waiting for $*"
fi fi
set -o errexit return $rc
return $status
} }
# Proxy is not started if S3PROXY_BINARY is an empty string # Proxy is not started if S3PROXY_BINARY is an empty string
@ -268,20 +265,18 @@ function start_s3fs {
rm -f pid rm -f pid
if [ `uname` = "Darwin" ]; then if [ `uname` = "Darwin" ]; then
set +o errexit
TRYCOUNT=0 TRYCOUNT=0
while [ $TRYCOUNT -le ${RETRIES:=20} ]; do while [ $TRYCOUNT -le ${RETRIES:=20} ]; do
df | grep -q $TEST_BUCKET_MOUNT_POINT_1 df | grep -q $TEST_BUCKET_MOUNT_POINT_1 && rc=$? || rc=$?
if [ $? -eq 0 ]; then if [ $rc -eq 0 ]; then
break; break;
fi fi
sleep 1 sleep 1
TRYCOUNT=`expr ${TRYCOUNT} + 1` TRYCOUNT=`expr ${TRYCOUNT} + 1`
done done
if [ $? -ne 0 ]; then if [ $rc -ne 0 ]; then
exit 1 exit 1
fi fi
set -o errexit
else else
retry ${RETRIES:=20} grep -q $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts || exit 1 retry ${RETRIES:=20} grep -q $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts || exit 1
fi fi

View File

@ -235,22 +235,12 @@ function run_suite {
key_prefix="testrun-$RANDOM" key_prefix="testrun-$RANDOM"
cd_run_dir $key_prefix cd_run_dir $key_prefix
for t in "${TEST_LIST[@]}"; do for t in "${TEST_LIST[@]}"; do
# The following sequence runs tests in a subshell to allow continuation $t $key_prefix && rc=$? || rc=$?
# on test failure, but still allowing errexit to be in effect during if [[ $rc == 0 ]] ; then
# the test.
#
# See:
# https://groups.google.com/d/msg/gnu.bash.bug/NCK_0GmIv2M/dkeZ9MFhPOIJ
# Other ways of trying to capture the return value will also disable
# errexit in the function due to bash... compliance with POSIX?
set +o errexit
(set -o errexit; $t $key_prefix)
if [[ $? == 0 ]]; then
report_pass $t report_pass $t
else else
report_fail $t report_fail $t
fi fi
set -o errexit
done done
cd ${orig_dir} cd ${orig_dir}
clean_run_dir clean_run_dir