simplify the retry implementation and tests

This commit is contained in:
Earl Warren 2023-11-01 18:40:23 +01:00
parent 9d138db73c
commit 15dc3ec7a7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 29 additions and 18 deletions

View file

@ -171,17 +171,27 @@ function unit_retry() {
# Succeeds after two tries
#
echo 2 > $TMPDIR/unit_retry_two
RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log
if ! RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
cat $TMPDIR/retry.test-log
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" = 2
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2 ; then
cat $TMPDIR/retry.test-log
return 1
fi
#
# Succeeds immediately
#
RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log
if ! RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" = 0
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0 ; then
cat $TMPDIR/retry.test-log
return 1
fi
#
# Verify the output is only the output of the last run and is not polluted by
@ -194,7 +204,8 @@ function unit_retry() {
# Fails after one try
#
echo 2 > $TMPDIR/unit_retry_two
if RETRY_DELAYS='1' retry unit_retry_fail $two |& tee $TMPDIR/retry.test-log ; then
if RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
return 1
fi
grep --quiet 'retry failed' $TMPDIR/retry.test-log
@ -368,8 +379,7 @@ function integration() {
}
function unit() {
# do not run in debug mode, it will polute the output and fail
${BASH_SOURCE[0]} --verbose unit_retry
unit_retry
}
function run_tests() {