Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add a benchmark for pull merging #4908

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion integrations/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
package integrations

import (
"fmt"
"math/rand"
"net/http"
"strings"
"testing"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/test"
api "code.gitea.io/sdk/gitea"
"github.com/stretchr/testify/assert"
)

func BenchmarkRepo(b *testing.B) {
Expand Down Expand Up @@ -102,12 +106,49 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
branchCount := len(branches)
b.ResetTimer() //We measure from here
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "GET", "/%s/%s/commits/%s", owner.Name, repo.Name, branches[i%branchCount])
req := NewRequestf(b, "GET", "/%s/%s/commits/%s", owner.Name, repo.Name, branches[i%branchCount].Name)
session.MakeRequest(b, req, http.StatusOK)
}
})
})
}
}

func benchmarkPullMergeHelper(b *testing.B, style models.MergeStyle) {
repoName := "gitea"

prepareTestEnv(b)
session := loginUser(b, "user2")
testRepoMigrate(b, session, "https://github.com/go-gitea/gitea.git", repoName)

req := NewRequest(b, "GET", "/user/logout")
session.MakeRequest(b, req, http.StatusFound)

session = loginUser(b, "user1")
testRepoFork(b, session, "user2", repoName, "user1", repoName)

b.StopTimer()
b.ResetTimer()
for i := 0; i < b.N; i++ {
branchName := fmt.Sprintf("pull%d", i)
testEditFileToNewBranch(b, session, "user1", repoName, "master", branchName, "README.md", fmt.Sprintf("Hello, World (Edited) ver%d\n", i))
resp := testPullCreate(b, session, "user1", repoName, branchName, fmt.Sprintf("This is a pull title for v%d", i))
elem := strings.Split(test.RedirectURL(resp), "/")
assert.EqualValues(b, "pulls", elem[3])
b.StartTimer()
testPullMerge(b, session, elem[1], elem[2], elem[4], style)
b.StopTimer()
}
}

func BenchmarkPullMerge(b *testing.B) {
benchmarkPullMergeHelper(b, models.MergeStyleMerge)
}
func BenchmarkPullRebase(b *testing.B) {
benchmarkPullMergeHelper(b, models.MergeStyleRebase)
}
func BenchmarkPullSquash(b *testing.B) {
benchmarkPullMergeHelper(b, models.MergeStyleSquash)
}

//TODO list commits /repos/{owner}/{repo}/commits
4 changes: 2 additions & 2 deletions integrations/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {

}

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

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

// Get to the 'edit this file' page
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
Expand Down
2 changes: 1 addition & 1 deletion integrations/pull_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
)

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

Expand Down
2 changes: 1 addition & 1 deletion integrations/pull_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stretchr/testify/assert"
)

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

Expand Down
2 changes: 1 addition & 1 deletion integrations/repo_fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/stretchr/testify/assert"
)

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

// Step0: check the existence of the to-fork repo
Expand Down