Skip to content

Commit 08fcd16

Browse files
committed
Benchmark pull merge
1 parent 044d839 commit 08fcd16

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

integrations/benchmarks_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
package integrations
66

77
import (
8+
"fmt"
89
"math/rand"
910
"net/http"
11+
"strings"
1012
"testing"
1113

1214
"code.gitea.io/gitea/models"
15+
"code.gitea.io/gitea/modules/test"
1316
api "code.gitea.io/sdk/gitea"
17+
"github.com/stretchr/testify/assert"
1418
)
1519

1620
func BenchmarkRepo(b *testing.B) {
@@ -110,4 +114,41 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
110114
}
111115
}
112116

117+
func benchmarkPullMergeHelper(b *testing.B, style models.MergeStyle) {
118+
repoName := "gitea"
119+
120+
prepareTestEnv(b)
121+
session := loginUser(b, "user2")
122+
testRepoMigrate(b, session, "https://github.com/go-gitea/gitea.git", repoName)
123+
124+
req := NewRequest(b, "GET", "/user/logout")
125+
session.MakeRequest(b, req, http.StatusFound)
126+
127+
session = loginUser(b, "user1")
128+
testRepoFork(b, session, "user2", repoName, "user1", repoName)
129+
130+
b.StopTimer()
131+
b.ResetTimer()
132+
for i := 0; i < b.N; i++ {
133+
branchName := fmt.Sprintf("pull%d", i)
134+
testEditFileToNewBranch(b, session, "user1", repoName, "master", branchName, "README.md", fmt.Sprintf("Hello, World (Edited) ver%d\n", i))
135+
resp := testPullCreate(b, session, "user1", repoName, branchName, fmt.Sprintf("This is a pull title for v%d", i))
136+
elem := strings.Split(test.RedirectURL(resp), "/")
137+
assert.EqualValues(b, "pulls", elem[3])
138+
b.StartTimer()
139+
testPullMerge(b, session, elem[1], elem[2], elem[4], style)
140+
b.StopTimer()
141+
}
142+
}
143+
144+
func BenchmarkPullMerge(b *testing.B) {
145+
benchmarkPullMergeHelper(b, models.MergeStyleMerge)
146+
}
147+
func BenchmarkPullRebase(b *testing.B) {
148+
benchmarkPullMergeHelper(b, models.MergeStyleRebase)
149+
}
150+
func BenchmarkPullSquash(b *testing.B) {
151+
benchmarkPullMergeHelper(b, models.MergeStyleSquash)
152+
}
153+
113154
//TODO list commits /repos/{owner}/{repo}/commits

integrations/editor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
9090

9191
}
9292

93-
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) *httptest.ResponseRecorder {
93+
func testEditFile(t testing.TB, session *TestSession, user, repo, branch, filePath, newContent string) *httptest.ResponseRecorder {
9494
// Get to the 'edit this file' page
9595
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
9696
resp := session.MakeRequest(t, req, http.StatusOK)
@@ -119,7 +119,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
119119
return resp
120120
}
121121

122-
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *httptest.ResponseRecorder {
122+
func testEditFileToNewBranch(t testing.TB, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *httptest.ResponseRecorder {
123123

124124
// Get to the 'edit this file' page
125125
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))

integrations/pull_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
)
1616

17-
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, title string) *httptest.ResponseRecorder {
17+
func testPullCreate(t testing.TB, session *TestSession, user, repo, branch, title string) *httptest.ResponseRecorder {
1818
req := NewRequest(t, "GET", path.Join(user, repo))
1919
resp := session.MakeRequest(t, req, http.StatusOK)
2020

integrations/pull_merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/stretchr/testify/assert"
1919
)
2020

21-
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string, mergeStyle models.MergeStyle) *httptest.ResponseRecorder {
21+
func testPullMerge(t testing.TB, session *TestSession, user, repo, pullnum string, mergeStyle models.MergeStyle) *httptest.ResponseRecorder {
2222
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
2323
resp := session.MakeRequest(t, req, http.StatusOK)
2424

integrations/repo_fork_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stretchr/testify/assert"
1616
)
1717

18-
func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
18+
func testRepoFork(t testing.TB, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
1919
forkOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
2020

2121
// Step0: check the existence of the to-fork repo

0 commit comments

Comments
 (0)