@@ -14,7 +14,7 @@ import (
1414 "github.com/stretchr/testify/assert"
1515)
1616
17- func TestCreateTaskForRunner_MaxParallelEnforcement (t * testing.T ) {
17+ func TestMaxParallelJobStatusAndCounting (t * testing.T ) {
1818 assert .NoError (t , unittest .PrepareTestDatabase ())
1919
2020 t .Run ("MaxParallelReached" , func (t * testing.T ) {
@@ -117,4 +117,72 @@ func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) {
117117 assert .NoError (t , err )
118118 assert .Equal (t , 5 , runningCount , "All jobs should be able to run without limit" )
119119 })
120+
121+ t .Run ("MaxParallelWrongValue" , func (t * testing.T ) {
122+ runID := int64 (30000 )
123+ jobID := "wrong-value-use-default-value-job"
124+
125+ // Create ActionRun first
126+ run := & actions_model.ActionRun {
127+ ID : runID ,
128+ RepoID : 1 ,
129+ OwnerID : 1 ,
130+ Index : 30000 ,
131+ Status : actions_model .StatusRunning ,
132+ }
133+ assert .NoError (t , db .Insert (context .Background (), run ))
134+
135+ // Test different invalid max-parallel values
136+ testCases := []struct {
137+ name string
138+ maxParallel int
139+ description string
140+ }{
141+ {
142+ name : "negative value" ,
143+ maxParallel : - 1 ,
144+ description : "Negative max-parallel should default to 0 (no limit)" ,
145+ },
146+ }
147+
148+ for _ , tc := range testCases {
149+ t .Run (tc .name , func (t * testing.T ) {
150+
151+ // Create jobs with the test max-parallel value
152+ for i := range 5 {
153+ job := & actions_model.ActionRunJob {
154+ RunID : runID ,
155+ RepoID : 1 ,
156+ OwnerID : 1 ,
157+ JobID : jobID ,
158+ Name : "Test Job " + tc .name ,
159+ Status : actions_model .StatusWaiting ,
160+ MaxParallel : tc .maxParallel ,
161+ }
162+ assert .NoError (t , db .Insert (context .Background (), job ))
163+
164+ // Verify the value was stored
165+ if i == 0 {
166+ storedJob , err := actions_model .GetRunJobByID (context .Background (), job .ID )
167+ assert .NoError (t , err )
168+ assert .Equal (t , tc .maxParallel , storedJob .MaxParallel , tc .description )
169+ }
170+ }
171+
172+ // All jobs can run simultaneously when max-parallel <= 0
173+ jobs , err := actions_model .GetRunJobsByRunID (context .Background (), runID )
174+ assert .NoError (t , err )
175+
176+ for _ , job := range jobs {
177+ job .Status = actions_model .StatusRunning
178+ _ , err := actions_model .UpdateRunJob (context .Background (), job , nil , "status" )
179+ assert .NoError (t , err )
180+ }
181+
182+ runningCount , err := actions_model .CountRunningJobsByWorkflowAndRun (context .Background (), runID , jobID )
183+ assert .NoError (t , err )
184+ assert .GreaterOrEqual (t , runningCount , 5 , "All jobs should be able to run when max-parallel is " + tc .name )
185+ })
186+ }
187+ })
120188}
0 commit comments