From f48fa029169d05e04f2a7fe13fbf099ffd9ed3e7 Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sun, 6 Oct 2024 16:53:11 +0200 Subject: [PATCH 1/4] WIP: Add test for schedule not being cancelled --- .../.forgejo/workflows/test.yml | 8 ++++++++ actions/example-schedule-noncancel/run.sh | 18 ++++++++++++++++++ actions/example-schedule-noncancel/teardown.sh | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 actions/example-schedule-noncancel/.forgejo/workflows/test.yml create mode 100755 actions/example-schedule-noncancel/run.sh create mode 100644 actions/example-schedule-noncancel/teardown.sh diff --git a/actions/example-schedule-noncancel/.forgejo/workflows/test.yml b/actions/example-schedule-noncancel/.forgejo/workflows/test.yml new file mode 100644 index 0000000..e0015c3 --- /dev/null +++ b/actions/example-schedule-noncancel/.forgejo/workflows/test.yml @@ -0,0 +1,8 @@ +on: + schedule: + - cron: "* * * * *" +jobs: + test: + runs-on: docker + steps: + - run: sleep 15 diff --git a/actions/example-schedule-noncancel/run.sh b/actions/example-schedule-noncancel/run.sh new file mode 100755 index 0000000..9fa275d --- /dev/null +++ b/actions/example-schedule-noncancel/run.sh @@ -0,0 +1,18 @@ +repo=root/example-$example +# +# push the repository +# +forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token +sha=$(forgejo-test-helper.sh branch_tip $url $repo main) +# +# wait for the workflow (sleep infinity) to start running +# +forgejo-test-helper.sh wait_running $url $repo $sha +# +# push to the same branch +# +forgejo-test-helper.sh push_workflow actions/example-echo $url root example-$example setup-forgejo $token +# +# wait for the workflow to be canceled as a result of the previous push +# +forgejo-test-helper.sh wait_success $url $repo $sha diff --git a/actions/example-schedule-noncancel/teardown.sh b/actions/example-schedule-noncancel/teardown.sh new file mode 100644 index 0000000..ae9987a --- /dev/null +++ b/actions/example-schedule-noncancel/teardown.sh @@ -0,0 +1,4 @@ +# +# this will effectively discard any linger workflow so they do not interfere with other tests +# +forgejo-runner.sh reload From 631055d190d2474a11affb0fb71704fabdd3710c Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sat, 12 Oct 2024 15:11:14 +0200 Subject: [PATCH 2/4] rewrite schedule cancelling test --- .../{test.yml => schedule_continue.yml} | 0 actions/example-schedule-noncancel/run.sh | 80 +++++++++++++++++-- 2 files changed, 74 insertions(+), 6 deletions(-) rename actions/example-schedule-noncancel/.forgejo/workflows/{test.yml => schedule_continue.yml} (100%) diff --git a/actions/example-schedule-noncancel/.forgejo/workflows/test.yml b/actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml similarity index 100% rename from actions/example-schedule-noncancel/.forgejo/workflows/test.yml rename to actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml diff --git a/actions/example-schedule-noncancel/run.sh b/actions/example-schedule-noncancel/run.sh index 9fa275d..5d0af81 100755 --- a/actions/example-schedule-noncancel/run.sh +++ b/actions/example-schedule-noncancel/run.sh @@ -1,18 +1,86 @@ repo=root/example-$example +# +# delete the repository +# +api=$url/api/v1 +forgejo-curl.sh api_json -X DELETE $api/repos/root/example-$example + # # push the repository # forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token -sha=$(forgejo-test-helper.sh branch_tip $url $repo main) + +# Prevent test failure because the db is occupied +sqlite3 $DIR/forgejo-work-path/forgejo.db "pragma busy_timeout=20000" + # -# wait for the workflow (sleep infinity) to start running +# get the run id of the workflow that just started # -forgejo-test-helper.sh wait_running $url $repo $sha +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 + # -# push to the same branch +# 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 + # -# wait for the workflow to be canceled as a result of the previous push +# Wait for the workflow to finish anyway # -forgejo-test-helper.sh wait_success $url $repo $sha +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" +} + +finished_status=$(checkFinished) +while [ -z $finished_status ]; do + echo waiting 5... + sleep 5 + finished_status=$(checkFinished) +done + +echo Workflow finished. + +test $finished_status = 1 From c3eb8918b444b8262db0e7c24db9863338a1b20c Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sun, 13 Oct 2024 12:45:19 +0200 Subject: [PATCH 3/4] implement waiting based on a file --- .../.forgejo/workflows/schedule_continue.yml | 8 +++++++- actions/example-schedule-noncancel/run.sh | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml b/actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml index e0015c3..8fe7177 100644 --- a/actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml +++ b/actions/example-schedule-noncancel/.forgejo/workflows/schedule_continue.yml @@ -4,5 +4,11 @@ on: jobs: test: runs-on: docker + container: + image: code.forgejo.org/oci/debian:bookworm + options: "--volume /srv/example:/srv/example" steps: - - run: sleep 15 + - run: | + while ! [ -f /srv/example/schedule-noncancel/PUSHED ]; do + sleep 3 + done diff --git a/actions/example-schedule-noncancel/run.sh b/actions/example-schedule-noncancel/run.sh index 5d0af81..810e634 100755 --- a/actions/example-schedule-noncancel/run.sh +++ b/actions/example-schedule-noncancel/run.sh @@ -3,7 +3,9 @@ repo=root/example-$example # delete the repository # api=$url/api/v1 -forgejo-curl.sh api_json -X DELETE $api/repos/root/example-$example +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 @@ -61,6 +63,10 @@ echo Push to 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 # @@ -71,7 +77,7 @@ checkFinished() { "select status \ from action_run \ where id = $run_id \ - and status != 6" + and (status != 6 and status != 5)" } finished_status=$(checkFinished) From 222313181f79c1d9e72064224393470446e19685 Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sun, 13 Oct 2024 13:57:07 +0200 Subject: [PATCH 4/4] Add schedule-noncancel test to 9.0 suite --- actions/actions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/actions.sh b/actions/actions.sh index 7bcc4df..9701e39 100755 --- a/actions/actions.sh +++ b/actions/actions.sh @@ -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 }