Merge pull request 'Add test for schedule not being cancelled' (#289) from Kwonunn/end-to-end:schedule-noncancel-test into main
Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/289 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
This commit is contained in:
commit
800cfcc0a8
4 changed files with 111 additions and 0 deletions
|
@ -141,6 +141,7 @@ function test_actions() {
|
|||
|
||||
if dpkg --compare-versions $version ge 9.0; then
|
||||
run actions_verify_feature logs-compression
|
||||
run actions_verify_example schedule-noncancel
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
on:
|
||||
schedule:
|
||||
- cron: "* * * * *"
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: code.forgejo.org/oci/debian:bookworm
|
||||
options: "--volume /srv/example:/srv/example"
|
||||
steps:
|
||||
- run: |
|
||||
while ! [ -f /srv/example/schedule-noncancel/PUSHED ]; do
|
||||
sleep 3
|
||||
done
|
92
actions/example-schedule-noncancel/run.sh
Executable file
92
actions/example-schedule-noncancel/run.sh
Executable file
|
@ -0,0 +1,92 @@
|
|||
repo=root/example-$example
|
||||
#
|
||||
# delete the repository
|
||||
#
|
||||
api=$url/api/v1
|
||||
if forgejo-curl.sh api_json -X GET $api/repos/root/example-$example; then
|
||||
forgejo-curl.sh api_json -X DELETE $api/repos/root/example-$example
|
||||
fi
|
||||
|
||||
#
|
||||
# push the repository
|
||||
#
|
||||
forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token
|
||||
|
||||
# Prevent test failure because the db is occupied
|
||||
sqlite3 $DIR/forgejo-work-path/forgejo.db "pragma busy_timeout=20000"
|
||||
|
||||
#
|
||||
# get the run id of the workflow that just started
|
||||
#
|
||||
getScheduleRun() {
|
||||
sqlite3 $DIR/forgejo-work-path/forgejo.db \
|
||||
"select action_run.id \
|
||||
from action_run \
|
||||
inner join action_schedule on action_run.schedule_id = action_schedule.id \
|
||||
inner join repository on action_schedule.repo_id = repository.id \
|
||||
where repository.name = 'example-schedule-noncancel' \
|
||||
order by action_run.created desc limit 1"
|
||||
}
|
||||
|
||||
run_id=$(getScheduleRun)
|
||||
while [ -z $run_id ]; do
|
||||
echo waiting 5...
|
||||
sleep 5
|
||||
run_id=$(getScheduleRun)
|
||||
done
|
||||
|
||||
echo Schedule run id: $run_id
|
||||
|
||||
#
|
||||
# Wait for it to be started
|
||||
#
|
||||
checkStarted() {
|
||||
sqlite3 $DIR/forgejo-work-path/forgejo.db \
|
||||
"select id \
|
||||
from action_run \
|
||||
where id = $run_id \
|
||||
and started is not null"
|
||||
}
|
||||
|
||||
started_check=$(checkStarted)
|
||||
while [ -z $started_check ]; do
|
||||
echo waiting 2...
|
||||
sleep 2
|
||||
started_check=$(checkStarted)
|
||||
done
|
||||
|
||||
echo Run has started
|
||||
echo Push to repo again
|
||||
|
||||
#
|
||||
# Push to the repo again
|
||||
#
|
||||
forgejo-test-helper.sh push_workflow actions/example-echo $url root example-$example setup-forgejo $token
|
||||
|
||||
echo Signal to the workflow that the push has happened
|
||||
mkdir -p /srv/example/schedule-noncancel
|
||||
touch /srv/example/schedule-noncancel/PUSHED
|
||||
|
||||
#
|
||||
# Wait for the workflow to finish anyway
|
||||
#
|
||||
echo Wait for workflow to finish
|
||||
|
||||
checkFinished() {
|
||||
sqlite3 $DIR/forgejo-work-path/forgejo.db \
|
||||
"select status \
|
||||
from action_run \
|
||||
where id = $run_id \
|
||||
and (status != 6 and status != 5)"
|
||||
}
|
||||
|
||||
finished_status=$(checkFinished)
|
||||
while [ -z $finished_status ]; do
|
||||
echo waiting 5...
|
||||
sleep 5
|
||||
finished_status=$(checkFinished)
|
||||
done
|
||||
|
||||
echo Workflow finished.
|
||||
|
||||
test $finished_status = 1
|
4
actions/example-schedule-noncancel/teardown.sh
Normal file
4
actions/example-schedule-noncancel/teardown.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#
|
||||
# this will effectively discard any linger workflow so they do not interfere with other tests
|
||||
#
|
||||
forgejo-runner.sh reload
|
Loading…
Add table
Reference in a new issue