diff --git a/integrations/benchmarks_test.go b/integrations/benchmarks_test.go index 7c4196f2b9db..313be7198a4d 100644 --- a/integrations/benchmarks_test.go +++ b/integrations/benchmarks_test.go @@ -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) { @@ -102,7 +106,7 @@ 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) } }) @@ -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 diff --git a/integrations/editor_test.go b/integrations/editor_test.go index e2dd2e1dc4b8..973451ddf8c5 100644 --- a/integrations/editor_test.go +++ b/integrations/editor_test.go @@ -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) @@ -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)) diff --git a/integrations/pull_create_test.go b/integrations/pull_create_test.go index 1d53aa3b6e4f..6514602050bc 100644 --- a/integrations/pull_create_test.go +++ b/integrations/pull_create_test.go @@ -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) diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index b375a55f53b2..20c982a64a2c 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -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) diff --git a/integrations/repo_fork_test.go b/integrations/repo_fork_test.go index 64bc46f7771c..e3a0388ab457 100644 --- a/integrations/repo_fork_test.go +++ b/integrations/repo_fork_test.go @@ -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