Skip to content

Commit b65b329

Browse files
committed
fix test
1 parent 1180237 commit b65b329

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

services/actions/clear_tasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository) er
5757
return err
5858
}
5959

60-
func CancelConcurrentJobs(ctx context.Context, job *actions_model.ActionRunJob) error {
60+
func CancelJobs(ctx context.Context, job *actions_model.ActionRunJob) error {
6161
jobs, err := actions_model.CancelPreviousJobsByConcurrency(ctx, job)
6262
notifyWorkflowJobStatusUpdate(ctx, jobs)
6363
return err

services/actions/job_emitter.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ func checkJobsByRunID(ctx context.Context, runID int64) error {
5353
if err != nil {
5454
return fmt.Errorf("get action run: %w", err)
5555
}
56+
var jobs, updatedJobs []*actions_model.ActionRunJob
5657
if err := db.WithTx(ctx, func(ctx context.Context) error {
5758
// check jobs of the current run
58-
if err := checkJobsOfRun(ctx, run); err != nil {
59+
if js, ujs, err := checkJobsOfRun(ctx, run); err != nil {
5960
return err
61+
} else {
62+
jobs = append(jobs, js...)
63+
updatedJobs = append(updatedJobs, ujs...)
6064
}
6165
// check run (workflow-level) concurrency
6266
concurrentRunIDs := make(container.Set[int64])
@@ -78,8 +82,11 @@ func checkJobsByRunID(ctx context.Context, runID int64) error {
7882
if concurrentRun.NeedApproval {
7983
continue
8084
}
81-
if err := checkJobsOfRun(ctx, concurrentRun); err != nil {
85+
if js, ujs, err := checkJobsOfRun(ctx, concurrentRun); err != nil {
8286
return err
87+
} else {
88+
jobs = append(jobs, js...)
89+
updatedJobs = append(updatedJobs, ujs...)
8390
}
8491
updatedRun, err := actions_model.GetRunByID(ctx, concurrentRun.ID)
8592
if err != nil {
@@ -128,8 +135,11 @@ func checkJobsByRunID(ctx context.Context, runID int64) error {
128135
if concurrentRun.NeedApproval {
129136
continue
130137
}
131-
if err := checkJobsOfRun(ctx, concurrentRun); err != nil {
138+
if js, ujs, err := checkJobsOfRun(ctx, concurrentRun); err != nil {
132139
return err
140+
} else {
141+
jobs = append(jobs, js...)
142+
updatedJobs = append(updatedJobs, ujs...)
133143
}
134144
updatedJob, err := actions_model.GetRunJobByID(ctx, concurrentJob.ID)
135145
if err != nil {
@@ -142,27 +152,29 @@ func checkJobsByRunID(ctx context.Context, runID int64) error {
142152
}
143153
}
144154
}
145-
146155
return nil
147156
}); err != nil {
148157
return err
149158
}
150-
159+
CreateCommitStatus(ctx, jobs...)
160+
for _, job := range updatedJobs {
161+
_ = job.LoadAttributes(ctx)
162+
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
163+
}
151164
return nil
152165
}
153166

154-
func checkJobsOfRun(ctx context.Context, run *actions_model.ActionRun) error {
155-
jobs, err := db.Find[actions_model.ActionRunJob](ctx, actions_model.FindRunJobOptions{RunID: run.ID})
167+
func checkJobsOfRun(ctx context.Context, run *actions_model.ActionRun) (jobs, updatedJobs []*actions_model.ActionRunJob, err error) {
168+
jobs, err = db.Find[actions_model.ActionRunJob](ctx, actions_model.FindRunJobOptions{RunID: run.ID})
156169
if err != nil {
157-
return err
170+
return
158171
}
159-
var updatedjobs []*actions_model.ActionRunJob
160172
vars, err := actions_model.GetVariablesOfRun(ctx, run)
161173
if err != nil {
162-
return fmt.Errorf("get run %d variables: %w", run.ID, err)
174+
return
163175
}
164176

165-
if err := db.WithTx(ctx, func(ctx context.Context) error {
177+
if err = db.WithTx(ctx, func(ctx context.Context) error {
166178
for _, job := range jobs {
167179
job.Run = run
168180
}
@@ -176,19 +188,15 @@ func checkJobsOfRun(ctx context.Context, run *actions_model.ActionRun) error {
176188
} else if n != 1 {
177189
return fmt.Errorf("no affected for updating blocked job %v", job.ID)
178190
}
179-
updatedjobs = append(updatedjobs, job)
191+
updatedJobs = append(updatedJobs, job)
180192
}
181193
}
182194
return nil
183195
}); err != nil {
184-
return err
185-
}
186-
CreateCommitStatus(ctx, jobs...)
187-
for _, job := range updatedjobs {
188-
_ = job.LoadAttributes(ctx)
189-
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
196+
return
190197
}
191-
return nil
198+
199+
return
192200
}
193201

194202
type jobStatusResolver struct {

services/actions/task.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func PickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
5353
return nil
5454
}
5555

56-
if err := CancelConcurrentJobs(ctx, t.Job); err != nil {
57-
return fmt.Errorf("CancelConcurrentJobs: %w", err)
56+
if err := CancelJobs(ctx, t.Job); err != nil {
57+
return fmt.Errorf("CancelJobs: %w", err)
5858
}
5959

6060
if err := t.LoadAttributes(ctx); err != nil {

tests/integration/actions_concurrency_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ jobs:
224224
},
225225
ContentBase64: base64.StdEncoding.EncodeToString([]byte("user4-fix")),
226226
})(t)
227-
doAPICreatePullRequest(user4APICtx, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, user4.Name+"%s:bugfix/bbb")(t)
227+
doAPICreatePullRequest(user4APICtx, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, user4.Name+":bugfix/bbb")(t)
228228
// cannot fetch the task because an approval is required
229229
runner.fetchNoTask(t)
230230
// user2 approves the run
@@ -264,7 +264,7 @@ jobs:
264264
},
265265
ContentBase64: base64.StdEncoding.EncodeToString([]byte("user4-fix2")),
266266
})(t)
267-
doAPICreatePullRequest(user4APICtx, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, user4.Name+"%s:do-not-cancel/ccc")(t)
267+
doAPICreatePullRequest(user4APICtx, baseRepo.OwnerName, baseRepo.Name, baseRepo.DefaultBranch, user4.Name+":do-not-cancel/ccc")(t)
268268
// cannot fetch the task because cancel-in-progress is false
269269
runner.fetchNoTask(t)
270270
runner.execTask(t, pr2Task1, &mockTaskOutcome{

0 commit comments

Comments
 (0)