Skip to content

Commit

Permalink
Benchmark pull merge
Browse files Browse the repository at this point in the history
  • Loading branch information
typeless committed Dec 21, 2018
1 parent 044d839 commit 08fcd16
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
41 changes: 41 additions & 0 deletions 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 @@ -110,4 +114,41 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
}
}

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

0 comments on commit 08fcd16

Please sign in to comment.