Skip to content

Commit 94ffa82

Browse files
committed
TestMatrixConcurrency
1 parent 64bf223 commit 94ffa82

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

services/actions/run.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ func InsertRun(ctx context.Context, run *actions_model.ActionRun, jobs []*jobpar
115115
}
116116
}
117117

118-
runJobs = append(runJobs, runJob)
119-
}
118+
if err := db.Insert(ctx, runJob); err != nil {
119+
return err
120+
}
120121

121-
if err := db.Insert(ctx, runJobs); err != nil {
122-
return err
122+
runJobs = append(runJobs, runJob)
123123
}
124124

125125
run.Status = actions_model.AggregateJobStatus(runJobs)

tests/integration/actions_concurrency_test.go

+80
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,86 @@ jobs:
402402
})
403403
}
404404

405+
func TestMatrixConcurrency(t *testing.T) {
406+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
407+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
408+
session := loginUser(t, user2.Name)
409+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
410+
411+
apiRepo := createActionsTestRepo(t, token, "actions-concurrency", false)
412+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
413+
httpContext := NewAPITestContext(t, user2.Name, repo.Name, auth_model.AccessTokenScopeWriteRepository)
414+
defer doAPIDeleteRepository(httpContext)(t)
415+
416+
linuxRunner := newMockRunner()
417+
linuxRunner.registerAsRepoRunner(t, user2.Name, repo.Name, "mock-linux-runner", []string{"linux-runner"})
418+
windowsRunner := newMockRunner()
419+
windowsRunner.registerAsRepoRunner(t, user2.Name, repo.Name, "mock-windows-runner", []string{"windows-runner"})
420+
darwinRunner := newMockRunner()
421+
darwinRunner.registerAsRepoRunner(t, user2.Name, repo.Name, "mock-darwin-runner", []string{"darwin-runner"})
422+
423+
wf1TreePath := ".gitea/workflows/concurrent-workflow-1.yml"
424+
wf1FileContent := `name: concurrent-workflow-1
425+
on:
426+
push:
427+
paths:
428+
- '.gitea/workflows/concurrent-workflow-1.yml'
429+
jobs:
430+
job1:
431+
runs-on: ${{ matrix.os }}-runner
432+
strategy:
433+
matrix:
434+
os: [windows, linux]
435+
concurrency:
436+
group: job-os-${{ matrix.os }}
437+
steps:
438+
- run: echo 'job1'
439+
job2:
440+
runs-on: ${{ matrix.os }}-runner
441+
strategy:
442+
matrix:
443+
os: [darwin, windows, linux]
444+
concurrency:
445+
group: job-os-${{ matrix.os }}
446+
steps:
447+
- run: echo 'job2'
448+
`
449+
450+
opts1 := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, fmt.Sprintf("create %s", wf1TreePath), wf1FileContent)
451+
createWorkflowFile(t, token, user2.Name, repo.Name, wf1TreePath, opts1)
452+
453+
job1WinTask := windowsRunner.fetchTask(t)
454+
job1LinuxTask := linuxRunner.fetchTask(t)
455+
windowsRunner.fetchNoTask(t)
456+
linuxRunner.fetchNoTask(t)
457+
job2DarwinTask := darwinRunner.fetchTask(t)
458+
_, job1WinJob, _ := getTaskAndJobAndRunByTaskID(t, job1WinTask.Id)
459+
assert.Equal(t, "job1 (windows)", job1WinJob.Name)
460+
assert.Equal(t, "job-os-windows", job1WinJob.ConcurrencyGroup)
461+
_, job1LinuxJob, _ := getTaskAndJobAndRunByTaskID(t, job1LinuxTask.Id)
462+
assert.Equal(t, "job1 (linux)", job1LinuxJob.Name)
463+
assert.Equal(t, "job-os-linux", job1LinuxJob.ConcurrencyGroup)
464+
_, job2DarwinJob, _ := getTaskAndJobAndRunByTaskID(t, job2DarwinTask.Id)
465+
assert.Equal(t, "job2 (darwin)", job2DarwinJob.Name)
466+
assert.Equal(t, "job-os-darwin", job2DarwinJob.ConcurrencyGroup)
467+
windowsRunner.execTask(t, job1WinTask, &mockTaskOutcome{
468+
result: runnerv1.Result_RESULT_SUCCESS,
469+
})
470+
linuxRunner.execTask(t, job1LinuxTask, &mockTaskOutcome{
471+
result: runnerv1.Result_RESULT_SUCCESS,
472+
})
473+
474+
job2WinTask := windowsRunner.fetchTask(t)
475+
job2LinuxTask := linuxRunner.fetchTask(t)
476+
_, job2WinJob, _ := getTaskAndJobAndRunByTaskID(t, job2WinTask.Id)
477+
assert.Equal(t, "job2 (windows)", job2WinJob.Name)
478+
assert.Equal(t, "job-os-windows", job2WinJob.ConcurrencyGroup)
479+
_, job2LinuxJob, _ := getTaskAndJobAndRunByTaskID(t, job2LinuxTask.Id)
480+
assert.Equal(t, "job2 (linux)", job2LinuxJob.Name)
481+
assert.Equal(t, "job-os-linux", job2LinuxJob.ConcurrencyGroup)
482+
})
483+
}
484+
405485
func TestWorkflowDispatchConcurrency(t *testing.T) {
406486
onGiteaRun(t, func(t *testing.T, u *url.URL) {
407487
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})

0 commit comments

Comments
 (0)