mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-12 15:33:39 +02:00
feat: Update the db migration and the add a debug message about wrong parsed values
This commit is contained in:
parent
704800ec07
commit
b85e78efeb
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/actions/jobparser"
|
"code.gitea.io/gitea/modules/actions/jobparser"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
notify_service "code.gitea.io/gitea/services/notify"
|
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
|
runJob.TokenPermissions = perms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Extract max-parallel from strategy if present
|
// Extract max-parallel from strategy if present
|
||||||
if job.Strategy.MaxParallelString != "" {
|
if job.Strategy.MaxParallelString != "" {
|
||||||
if maxParallel, err := strconv.Atoi(job.Strategy.MaxParallelString); err == nil && maxParallel > 0 {
|
if maxParallel, err := strconv.Atoi(job.Strategy.MaxParallelString); err == nil && maxParallel > 0 {
|
||||||
runJob.MaxParallel = maxParallel
|
runJob.MaxParallel = maxParallel
|
||||||
|
} else {
|
||||||
|
log.Debug("failed to process max-parallel for job %s: invalid value %v: %v", id, job.Strategy.MaxParallelString, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) {
|
func TestMaxParallelJobStatusAndCounting(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
t.Run("MaxParallelReached", func(t *testing.T) {
|
t.Run("MaxParallelReached", func(t *testing.T) {
|
||||||
@ -117,4 +117,72 @@ func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 5, runningCount, "All jobs should be able to run without limit")
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user