Skip to content

Commit

Permalink
TestScheduleConcurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettat123 committed Jan 21, 2025
1 parent fc3188e commit 8649497
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/actions_concurrency_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"context"
"encoding/base64"
"fmt"
"net/http"
Expand All @@ -17,6 +18,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
actions_service "code.gitea.io/gitea/services/actions"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -489,6 +491,50 @@ jobs:
})
}

func TestScheduleConcurrency(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)

apiRepo := createActionsTestRepo(t, token, "actions-concurrency", false)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
runner := newMockRunner()
runner.registerAsRepoRunner(t, user2.Name, repo.Name, "mock-runner", []string{"ubuntu-latest"})

// add a variable for test
req := NewRequestWithJSON(t, "POST",
fmt.Sprintf("/api/v1/repos/%s/%s/actions/variables/cancel_schedule", user2.Name, repo.Name), &api.CreateVariableOption{
Value: "false",
}).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)

wf1TreePath := ".gitea/workflows/schedule-concurrency.yml"
wf1FileContent := `name: schedule-concurrency
on:
schedule:
- cron: '0/5 * * * *'
concurrency:
group: schedule-concurrency
cancel-in-progress: ${{ vars.cancel_schedule == 'false' }}
jobs:
job:
runs-on: ubuntu-latest
steps:
- run: echo 'workflow dispatch job'
`

opts1 := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, fmt.Sprintf("create %s", wf1TreePath), wf1FileContent)
createWorkflowFile(t, token, user2.Name, repo.Name, wf1TreePath, opts1)

assert.NoError(t, actions_service.StartScheduleTasks(context.Background()))

httpContext := NewAPITestContext(t, user2.Name, repo.Name, auth_model.AccessTokenScopeWriteRepository)
doAPIDeleteRepository(httpContext)(t)
})
}

func getTaskAndJobAndRunByTaskID(t *testing.T, taskID int64) (*actions_model.ActionTask, *actions_model.ActionRunJob, *actions_model.ActionRun) {
actionTask := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: taskID})
actionRunJob := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunJob{ID: actionTask.JobID})
Expand Down

0 comments on commit 8649497

Please sign in to comment.