mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
## Fixes #36983 ## Summary 1. Add transitional `Cancelling` status (between `Running` and `Cancelled`); cancel flow marks active tasks `Cancelling`, runner finalizes to `Cancelled` on terminal result. 2. Taskless jobs cancel directly (no runner to finalize). 3. Runner-protocol responses map `Cancelling` → `RESULT_CANCELLED`. 4. Run/job aggregation treats `Cancelling` as active. 5. Status mapping/aggregation tests + en-US locale added. **Problem** When a workflow was cancelled from the UI, jobs were marked cancelled immediately, which could skip post-run cleanup behavior. ## Solution Use a transitional status path: Running → Cancelling → Cancelled This allows runner finalization and cleanup path execution before final terminal state. **Testing** > 1. go test -tags "sqlite sqlite_unlock_notify" ./models/actions -run "TestAggregateJobStatus|TestStatusAsResult|TestStatusFromResult" > 2. go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4 run ./models/actions/... ./routers/api/actions/runner/... ## Related - act_runner: https://gitea.com/gitea/act_runner/pulls/825 — independent; this PR's capability gate keeps legacy runners on the immediate-cancel path. The new flow activates only for runners that advertise the `cancelling` capability. Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: Zettat123 <zettat123@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
91 lines
2.5 KiB
Go
91 lines
2.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
actions_model "code.gitea.io/gitea/models/actions"
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func createConflictingCancellingJob(t *testing.T, concurrencyGroup string, runIndex int64) *actions_model.ActionRunJob {
|
|
t.Helper()
|
|
|
|
run := &actions_model.ActionRun{
|
|
RepoID: 1,
|
|
OwnerID: 2,
|
|
TriggerUserID: 2,
|
|
WorkflowID: "test.yml",
|
|
Index: runIndex,
|
|
Ref: "refs/heads/main",
|
|
Status: actions_model.StatusBlocked,
|
|
}
|
|
require.NoError(t, db.Insert(t.Context(), run))
|
|
|
|
attempt := &actions_model.ActionRunAttempt{
|
|
RepoID: run.RepoID,
|
|
RunID: run.ID,
|
|
Attempt: 1,
|
|
TriggerUserID: run.TriggerUserID,
|
|
Status: actions_model.StatusBlocked,
|
|
ConcurrencyGroup: concurrencyGroup,
|
|
}
|
|
require.NoError(t, db.Insert(t.Context(), attempt))
|
|
|
|
job := &actions_model.ActionRunJob{
|
|
RunID: run.ID,
|
|
RunAttemptID: attempt.ID,
|
|
AttemptJobID: 1,
|
|
RepoID: run.RepoID,
|
|
OwnerID: run.OwnerID,
|
|
CommitSHA: "c2d72f548424103f01ee1dc02889c1e2bff816b0",
|
|
Name: "conflicting-cancelling-job",
|
|
JobID: "conflicting-cancelling-job",
|
|
Status: actions_model.StatusCancelling,
|
|
ConcurrencyGroup: concurrencyGroup,
|
|
}
|
|
require.NoError(t, db.Insert(t.Context(), job))
|
|
|
|
return job
|
|
}
|
|
|
|
func TestShouldBlockJobByConcurrency_CancellingJobBlocks(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
const concurrencyGroup = "test-cancelling-job-blocks"
|
|
createConflictingCancellingJob(t, concurrencyGroup, 9903)
|
|
|
|
job := &actions_model.ActionRunJob{
|
|
RepoID: 1,
|
|
RawConcurrency: concurrencyGroup,
|
|
IsConcurrencyEvaluated: true,
|
|
ConcurrencyGroup: concurrencyGroup,
|
|
}
|
|
|
|
shouldBlock, err := shouldBlockJobByConcurrency(t.Context(), job)
|
|
require.NoError(t, err)
|
|
assert.True(t, shouldBlock)
|
|
}
|
|
|
|
func TestShouldBlockRunByConcurrency_CancellingJobBlocks(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
const concurrencyGroup = "test-cancelling-run-blocks"
|
|
createConflictingCancellingJob(t, concurrencyGroup, 9904)
|
|
|
|
attempt := &actions_model.ActionRunAttempt{
|
|
RepoID: 1,
|
|
ConcurrencyGroup: concurrencyGroup,
|
|
}
|
|
|
|
shouldBlock, err := shouldBlockRunByConcurrency(t.Context(), attempt)
|
|
require.NoError(t, err)
|
|
assert.True(t, shouldBlock)
|
|
}
|