mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-27 20:33:44 +00:00
implement retry & tests
This commit is contained in:
parent
2666352130
commit
1cc9da66ff
2 changed files with 85 additions and 1 deletions
60
tests/run.sh
60
tests/run.sh
|
@ -92,7 +92,56 @@ function finalize_options() {
|
|||
options[password]=admin1234
|
||||
}
|
||||
|
||||
function run() {
|
||||
function unit_retry_fail() {
|
||||
local file=$1
|
||||
local value=$(cat $file)
|
||||
expr $value - 1 > $file
|
||||
echo RESULT
|
||||
if test $value -gt 0 ; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function unit_retry() {
|
||||
local two=$TMPDIR/unit_retry_two
|
||||
|
||||
rm -f $TMPDIR/retry.*
|
||||
|
||||
#
|
||||
# Succeeds after two tries
|
||||
#
|
||||
echo 2 > $TMPDIR/unit_retry_two
|
||||
RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.result 2> $TMPDIR/retry.log
|
||||
test "$(cat $TMPDIR/retry.result)" = "RESULT"
|
||||
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.log)" = 2
|
||||
|
||||
#
|
||||
# Succeeds immediately
|
||||
#
|
||||
RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.result 2> $TMPDIR/retry.log
|
||||
test "$(cat $TMPDIR/retry.result)" = "RESULT"
|
||||
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.log)" = 0
|
||||
|
||||
#
|
||||
# Verify the output is only the output of the last run and is not polluted by
|
||||
# unrelated output
|
||||
#
|
||||
echo 2 > $TMPDIR/unit_retry_two
|
||||
test "$(RETRY_DELAYS='1 1 1' retry unit_retry_fail $two)" = "RESULT"
|
||||
|
||||
#
|
||||
# Fails after one try
|
||||
#
|
||||
echo 2 > $TMPDIR/unit_retry_two
|
||||
if RETRY_DELAYS='1' retry unit_retry_fail $two |& tee $TMPDIR/retry.log ; then
|
||||
return 1
|
||||
fi
|
||||
grep --quiet 'retry failed' $TMPDIR/retry.log
|
||||
}
|
||||
|
||||
function integration() {
|
||||
user_create user2 user2@example.com
|
||||
forgejo-test-helper.sh push tests/destinationrepo http://user2:admin1234@${options[host_port]} user2 destinationrepo
|
||||
|
||||
|
@ -120,6 +169,15 @@ function run() {
|
|||
wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha)
|
||||
}
|
||||
|
||||
function unit() {
|
||||
unit_retry
|
||||
}
|
||||
|
||||
function run() {
|
||||
unit
|
||||
integration
|
||||
}
|
||||
|
||||
function main() {
|
||||
local command=run
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue