Skip to content

Commit 9f100d1

Browse files
committed
add Test_fixUnfinishedRunStatus
1 parent 0906916 commit 9f100d1

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

models/actions/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ func TestUpdateRepoRunsNumbers(t *testing.T) {
3030
err = UpdateRepoRunsNumbers(t.Context(), repo)
3131
assert.NoError(t, err)
3232
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
33-
assert.Equal(t, 4, repo.NumActionRuns)
33+
assert.Equal(t, 5, repo.NumActionRuns)
3434
assert.Equal(t, 3, repo.NumClosedActionRuns)
3535
}

models/fixtures/action_run.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,23 @@
159159
updated: 1683636626
160160
need_approval: 0
161161
approved_by: 0
162+
-
163+
id: 805
164+
title: "update actions"
165+
repo_id: 4
166+
owner_id: 1
167+
workflow_id: "artifact.yaml"
168+
index: 191
169+
trigger_user_id: 1
170+
ref: "refs/heads/master"
171+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
172+
event: "push"
173+
trigger_event: "push"
174+
is_fork_pull_request: 0
175+
status: 5
176+
started: 1683636528
177+
stopped: 1683636626
178+
created: 1683636108
179+
updated: 1683636626
180+
need_approval: 0
181+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,17 @@
143143
status: 1
144144
started: 1683636528
145145
stopped: 1683636626
146+
-
147+
id: 206
148+
run_id: 805
149+
repo_id: 4
150+
owner_id: 1
151+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
152+
is_fork_pull_request: 0
153+
name: job_2
154+
attempt: 1
155+
job_id: job_2
156+
task_id: 56
157+
status: 3
158+
started: 1683636528
159+
stopped: 1683636626

models/fixtures/action_task.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,22 @@
197197
log_length: 707
198198
log_size: 90179
199199
log_expired: 0
200+
-
201+
id: 56
202+
attempt: 1
203+
runner_id: 1
204+
status: 3 # 3 is the status code for "cancelled"
205+
started: 1683636528
206+
stopped: 1683636626
207+
repo_id: 4
208+
owner_id: 1
209+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
210+
is_fork_pull_request: 0
211+
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4240c64a69a2cc1508825121b7b8394e48e00b1bf3718b2aaaab
212+
token_salt: eeeeeeee
213+
token_last_eight: eeeeeeee
214+
log_filename: artifact-test2/2f/47.log
215+
log_in_storage: 1
216+
log_length: 707
217+
log_size: 90179
218+
log_expired: 0

models/fixtures/repo_unit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,10 @@
740740
type: 10
741741
config: "{}"
742742
created_unix: 946684810
743+
744+
-
745+
id: 112
746+
repo_id: 4
747+
type: 10
748+
config: "{}"
749+
created_unix: 946684810

services/doctor/actions_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package doctor
5+
6+
import (
7+
"testing"
8+
9+
actions_model "code.gitea.io/gitea/models/actions"
10+
"code.gitea.io/gitea/models/unittest"
11+
"code.gitea.io/gitea/modules/log"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func Test_fixUnfinishedRunStatus(t *testing.T) {
17+
assert.NoError(t, unittest.PrepareTestDatabase())
18+
19+
fixUnfinishedRunStatus(t.Context(), log.GetLogger(log.DEFAULT), true)
20+
21+
// check if the run is cancelled by id
22+
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: 805})
23+
assert.Equal(t, actions_model.StatusCancelled, run.Status)
24+
}

0 commit comments

Comments
 (0)