Skip to content

Commit 4d57c70

Browse files
committed
Add a pr creating parallel test
1 parent 39ca895 commit 4d57c70

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/integration/pull_create_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/url"
1111
"path"
1212
"strings"
13+
"sync"
1314
"testing"
1415

1516
auth_model "code.gitea.io/gitea/models/auth"
@@ -294,6 +295,44 @@ func TestPullCreatePrFromBaseToFork(t *testing.T) {
294295
})
295296
}
296297

298+
func TestPullCreateParallel(t *testing.T) {
299+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
300+
sessionFork := loginUser(t, "user1")
301+
testRepoFork(t, sessionFork, "user2", "repo1", "user1", "repo1", "")
302+
303+
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"})
304+
assert.Equal(t, 3, repo1.NumPulls)
305+
assert.Equal(t, 3, repo1.NumOpenPulls)
306+
307+
var wg sync.WaitGroup
308+
for i := 0; i < 5; i++ {
309+
wg.Go(func() {
310+
branchName := fmt.Sprintf("new-branch-%d", i)
311+
testEditFileToNewBranch(t, sessionFork, "user1", "repo1", "master", branchName, "README.md", fmt.Sprintf("Hello, World (Edited) %d\n", i))
312+
313+
// Create a PR
314+
resp := testPullCreateDirectly(t, sessionFork, createPullRequestOptions{
315+
BaseRepoOwner: "user2",
316+
BaseRepoName: "repo1",
317+
BaseBranch: "master",
318+
HeadRepoOwner: "user1",
319+
HeadRepoName: "repo1",
320+
HeadBranch: branchName,
321+
Title: fmt.Sprintf("This is a pull title %d", i),
322+
})
323+
// check the redirected URL
324+
url := test.RedirectURL(resp)
325+
assert.Regexp(t, "^/user2/repo1/pulls/[0-9]*$", url)
326+
})
327+
}
328+
wg.Wait()
329+
330+
repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"})
331+
assert.Equal(t, 8, repo1.NumPulls)
332+
assert.Equal(t, 8, repo1.NumOpenPulls)
333+
})
334+
}
335+
297336
func TestCreateAgitPullWithReadPermission(t *testing.T) {
298337
onGiteaRun(t, func(t *testing.T, u *url.URL) {
299338
dstPath := t.TempDir()

0 commit comments

Comments
 (0)