mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-06 21:07:06 +02:00
fix: Remove MatrixID and Capacity functionality
This commit is contained in:
1 parent
57400c725e
commit
d5823e0431
5 files changed
+6
-291
No files matched your search
@@ -14,106 +14,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateTaskForRunner_CapacityEnforcement(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Run("RunnerAtCapacity", func(t *testing.T) {
|
||||
// Create runner with capacity 2
|
||||
runner := &actions_model.ActionRunner{
|
||||
UUID: "capacity-test-1",
|
||||
Name: "Capacity Test Runner",
|
||||
Capacity: 2,
|
||||
TokenHash: "capacity_test_hash_1",
|
||||
Token: "capacity_test_token_1",
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), runner))
|
||||
|
||||
// Create 2 running tasks
|
||||
for i := range 2 {
|
||||
task := &actions_model.ActionTask{
|
||||
JobID: int64(1000 + i),
|
||||
RunnerID: runner.ID,
|
||||
Status: actions_model.StatusRunning,
|
||||
RepoID: 1,
|
||||
OwnerID: 1,
|
||||
TokenHash: "task_hash_" + string(rune('1'+i)),
|
||||
Token: "task_token_" + string(rune('1'+i)),
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), task))
|
||||
}
|
||||
|
||||
// Verify runner is at capacity
|
||||
count, err := actions_model.CountRunningTasksByRunner(context.Background(), runner.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
// Try to create another task - should fail due to capacity
|
||||
// Note: This would be tested in actual CreateTaskForRunner which checks capacity
|
||||
// For now, verify the count
|
||||
assert.Equal(t, runner.Capacity, count, "Runner should be at capacity")
|
||||
})
|
||||
|
||||
t.Run("RunnerBelowCapacity", func(t *testing.T) {
|
||||
runner := &actions_model.ActionRunner{
|
||||
UUID: "capacity-test-2",
|
||||
Name: "Below Capacity Runner",
|
||||
Capacity: 5,
|
||||
TokenHash: "capacity_test_hash_2",
|
||||
Token: "capacity_test_token_2",
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), runner))
|
||||
|
||||
// Create 2 running tasks
|
||||
for i := range 2 {
|
||||
task := &actions_model.ActionTask{
|
||||
JobID: int64(2000 + i),
|
||||
RunnerID: runner.ID,
|
||||
Status: actions_model.StatusRunning,
|
||||
RepoID: 1,
|
||||
OwnerID: 1,
|
||||
TokenHash: "task_hash_2_" + string(rune('a'+i)),
|
||||
Token: "task_token_2_" + string(rune('a'+i)),
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), task))
|
||||
}
|
||||
|
||||
count, err := actions_model.CountRunningTasksByRunner(context.Background(), runner.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
assert.Less(t, count, runner.Capacity, "Runner should be below capacity")
|
||||
})
|
||||
|
||||
t.Run("UnlimitedCapacity", func(t *testing.T) {
|
||||
runner := &actions_model.ActionRunner{
|
||||
UUID: "capacity-test-3",
|
||||
Name: "Unlimited Runner",
|
||||
Capacity: 0, // 0 = unlimited
|
||||
TokenHash: "capacity_test_hash_3",
|
||||
Token: "capacity_test_token_3",
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), runner))
|
||||
|
||||
// Create many running tasks
|
||||
for i := range 10 {
|
||||
task := &actions_model.ActionTask{
|
||||
JobID: int64(3000 + i),
|
||||
RunnerID: runner.ID,
|
||||
Status: actions_model.StatusRunning,
|
||||
RepoID: 1,
|
||||
OwnerID: 1,
|
||||
TokenHash: "task_hash_3_" + string(rune('a'+i)),
|
||||
Token: "task_token_3_" + string(rune('a'+i)),
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), task))
|
||||
}
|
||||
|
||||
count, err := actions_model.CountRunningTasksByRunner(context.Background(), runner.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 10, count)
|
||||
// With capacity 0, there's no limit
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
@@ -218,79 +118,3 @@ func TestCreateTaskForRunner_MaxParallelEnforcement(t *testing.T) {
|
||||
assert.Equal(t, 5, runningCount, "All jobs should be able to run without limit")
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTaskForRunner_CombinedEnforcement(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Run("BothRunnerCapacityAndMaxParallel", func(t *testing.T) {
|
||||
// Create runner with capacity 3
|
||||
runner := &actions_model.ActionRunner{
|
||||
UUID: "combined-test",
|
||||
Name: "Combined Test Runner",
|
||||
Capacity: 3,
|
||||
TokenHash: "combined_test_hash",
|
||||
Token: "combined_test_token",
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), runner))
|
||||
|
||||
runID := int64(30000)
|
||||
jobID := "combined-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))
|
||||
|
||||
// Create jobs with max-parallel 2
|
||||
for range 5 {
|
||||
job := &actions_model.ActionRunJob{
|
||||
RunID: runID,
|
||||
RepoID: 1,
|
||||
OwnerID: 1,
|
||||
JobID: jobID,
|
||||
Name: "Combined Job",
|
||||
Status: actions_model.StatusWaiting,
|
||||
MaxParallel: 2,
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), job))
|
||||
}
|
||||
|
||||
// The most restrictive limit should apply
|
||||
// In this case: max-parallel = 2 (more restrictive than runner capacity = 3)
|
||||
jobs, err := actions_model.GetRunJobsByRunID(context.Background(), runID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Simulate starting jobs
|
||||
for i, job := range jobs[:2] {
|
||||
job.Status = actions_model.StatusRunning
|
||||
_, err := actions_model.UpdateRunJob(context.Background(), job, nil, "status")
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := &actions_model.ActionTask{
|
||||
JobID: job.ID,
|
||||
RunnerID: runner.ID,
|
||||
Status: actions_model.StatusRunning,
|
||||
RepoID: 1,
|
||||
OwnerID: 1,
|
||||
TokenHash: "combined_task_hash_" + string(rune('a'+i)),
|
||||
Token: "combined_task_token_" + string(rune('a'+i)),
|
||||
}
|
||||
assert.NoError(t, db.Insert(context.Background(), task))
|
||||
}
|
||||
|
||||
// Verify both limits
|
||||
runningTasks, err := actions_model.CountRunningTasksByRunner(context.Background(), runner.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, runningTasks)
|
||||
assert.Less(t, runningTasks, runner.Capacity, "Should be under runner capacity")
|
||||
|
||||
runningJobs, err := actions_model.CountRunningJobsByWorkflowAndRun(context.Background(), runID, jobID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, runningJobs, "Should respect max-parallel")
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user