diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-13 18:59:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-13 18:59:18 +0800 |
commit | c36a1bc766effd6cafd860548d6a911d503144c1 (patch) | |
tree | df5f11fb5070d7f36de77ef95cb70b5fbcfecf3c /tests | |
parent | 079ef568247f9216a6e66c7e6038e11cc2bdd5f5 (diff) | |
download | gitea-c36a1bc766effd6cafd860548d6a911d503144c1.tar.gz gitea-c36a1bc766effd6cafd860548d6a911d503144c1.zip |
Fix parallel creating commit status bug with tests (#21911) (#21989)
backport #21911
backport #21998
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/repo_commits_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index c9e7753596..95dbfbae5f 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -5,9 +5,11 @@ package integration import ( + "fmt" "net/http" "net/http/httptest" "path" + "sync" "testing" "code.gitea.io/gitea/modules/json" @@ -115,3 +117,32 @@ func TestRepoCommitsWithStatusFailure(t *testing.T) { func TestRepoCommitsWithStatusWarning(t *testing.T) { doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow") } + +func TestRepoCommitsStatusParallel(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + // Request repository commits page + req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master") + resp := session.MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + // Get first commit URL + commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href") + assert.True(t, exists) + assert.NotEmpty(t, commitURL) + + var wg sync.WaitGroup + for i := 0; i < 10; i++ { + wg.Add(1) + go func(parentT *testing.T, i int) { + parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) { + runBody := doAPICreateCommitStatus(NewAPITestContext(t, "user2", "repo1"), path.Base(commitURL), api.CommitStatusState("pending")) + runBody(t) + wg.Done() + }) + }(t, i) + } + wg.Wait() +} |