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

View File

@ -235,22 +235,12 @@ function run_suite {
key_prefix="testrun-$RANDOM"
cd_run_dir $key_prefix
for t in "${TEST_LIST[@]}"; do
# The following sequence runs tests in a subshell to allow continuation
# on test failure, but still allowing errexit to be in effect during
# 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
$t $key_prefix && rc=$? || rc=$?
if [[ $rc == 0 ]] ; then
report_pass $t
else
report_fail $t
fi
set -o errexit
done
cd ${orig_dir}
clean_run_dir