|
5 | 5 | package integrations |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "fmt" |
8 | 9 | "math/rand" |
9 | 10 | "net/http" |
| 11 | + "strings" |
10 | 12 | "testing" |
11 | 13 |
|
12 | 14 | "code.gitea.io/gitea/models" |
| 15 | + "code.gitea.io/gitea/modules/test" |
13 | 16 | api "code.gitea.io/sdk/gitea" |
| 17 | + "github.com/stretchr/testify/assert" |
14 | 18 | ) |
15 | 19 |
|
16 | 20 | func BenchmarkRepo(b *testing.B) { |
@@ -110,4 +114,41 @@ func BenchmarkRepoBranchCommit(b *testing.B) { |
110 | 114 | } |
111 | 115 | } |
112 | 116 |
|
| 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 | + |
113 | 154 | //TODO list commits /repos/{owner}/{repo}/commits |
0 commit comments