From b85e78efebbfd785a9cfdace89cb88b36d656c37 Mon Sep 17 00:00:00 2001 From: Pascal Zimmermann Date: Fri, 30 Jan 2026 08:13:02 +0100 Subject: [PATCH] feat: Update the db migration and the add a debug message about wrong parsed values --- services/actions/run.go | 4 +- services/actions/task_assignment_test.go | 70 +++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/services/actions/run.go b/services/actions/run.go index 2a796ca2f9..bec95fe7fc 100644 --- a/services/actions/run.go +++ b/services/actions/run.go @@ -10,6 +10,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/actions/jobparser" "code.gitea.io/gitea/modules/util" notify_service "code.gitea.io/gitea/services/notify" @@ -134,11 +135,12 @@ func InsertRun(ctx context.Context, run *actions_model.ActionRun, jobs []*jobpar runJob.TokenPermissions = perms } - // Extract max-parallel from strategy if present if job.Strategy.MaxParallelString != "" { if maxParallel, err := strconv.Atoi(job.Strategy.MaxParallelString); err == nil && maxParallel > 0 { runJob.MaxParallel = maxParallel + } else { + log.Debug("failed to process max-parallel for job %s: invalid value %v: %v", id, job.Strategy.MaxParallelString, err) } } diff --git a/services/actions/task_assignment_test.go b/services/actions/task_assignment_test.go index d9af3777f3..0da280185b 100644 --- a/services/actions/task_assignment_test.go +++ b/services/actions/task_assignment_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) { +func TestMaxParallelJobStatusAndCounting(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) t.Run("MaxParallelReached", func(t *testing.T) { @@ -117,4 +117,72 @@ func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 5, runningCount, "All jobs should be able to run without limit") }) + + t.Run("MaxParallelWrongValue", func(t *testing.T) { + runID := int64(30000) + jobID := "wrong-value-use-default-value-job" + + // Create ActionRun first + run := &actions_model.ActionRun{ + ID: runID, + RepoID: 1, + OwnerID: 1, + Index: 30000, + Status: actions_model.StatusRunning, + } + assert.NoError(t, db.Insert(context.Background(), run)) + + // Test different invalid max-parallel values + testCases := []struct { + name string + maxParallel int + description string + }{ + { + name: "negative value", + maxParallel: -1, + description: "Negative max-parallel should default to 0 (no limit)", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + + // Create jobs with the test max-parallel value + for i := range 5 { + job := &actions_model.ActionRunJob{ + RunID: runID, + RepoID: 1, + OwnerID: 1, + JobID: jobID, + Name: "Test Job " + tc.name, + Status: actions_model.StatusWaiting, + MaxParallel: tc.maxParallel, + } + assert.NoError(t, db.Insert(context.Background(), job)) + + // Verify the value was stored + if i == 0 { + storedJob, err := actions_model.GetRunJobByID(context.Background(), job.ID) + assert.NoError(t, err) + assert.Equal(t, tc.maxParallel, storedJob.MaxParallel, tc.description) + } + } + + // All jobs can run simultaneously when max-parallel <= 0 + jobs, err := actions_model.GetRunJobsByRunID(context.Background(), runID) + assert.NoError(t, err) + + for _, job := range jobs { + job.Status = actions_model.StatusRunning + _, err := actions_model.UpdateRunJob(context.Background(), job, nil, "status") + assert.NoError(t, err) + } + + runningCount, err := actions_model.CountRunningJobsByWorkflowAndRun(context.Background(), runID, jobID) + assert.NoError(t, err) + assert.GreaterOrEqual(t, runningCount, 5, "All jobs should be able to run when max-parallel is "+tc.name) + }) + } + }) }