Skip to content

Commit a82ce5b

Browse files
committed
Benchmark Integration TESTS
1 parent 42efa14 commit a82ce5b

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

integrations/api_repo_file_create_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,36 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
105105
}
106106
}
107107

108+
func BenchmarkAPICreateFileSmall(b *testing.B) {
109+
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
110+
b := t.(*testing.B)
111+
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
112+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
113+
114+
for n := 0; n < b.N; n++ {
115+
treePath := fmt.Sprintf("update/file%d.txt", n)
116+
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
117+
}
118+
})
119+
}
120+
121+
func BenchmarkAPICreateFileMedium(b *testing.B) {
122+
data := make([]byte, 10*1024*1024)
123+
124+
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
125+
b := t.(*testing.B)
126+
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
127+
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
128+
129+
b.ResetTimer()
130+
for n := 0; n < b.N; n++ {
131+
treePath := fmt.Sprintf("update/file%d.txt", n)
132+
copy(data, treePath)
133+
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
134+
}
135+
})
136+
}
137+
108138
func TestAPICreateFile(t *testing.T) {
109139
onGiteaRun(t, func(t *testing.T, u *url.URL) {
110140
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16

integrations/api_repo_file_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
api "code.gitea.io/gitea/modules/structs"
1111
)
1212

13-
func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName string) (*api.FileResponse, error) {
13+
func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
1414
opts := &repofiles.UpdateRepoFileOptions{
1515
OldBranch: branchName,
1616
TreePath: treePath,
17-
Content: "This is a NEW file",
17+
Content: content,
1818
IsNewFile: true,
1919
Author: nil,
2020
Committer: nil,
@@ -23,5 +23,5 @@ func createFileInBranch(user *models.User, repo *models.Repository, treePath, br
2323
}
2424

2525
func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
26-
return createFileInBranch(user, repo, treePath, repo.DefaultBranch)
26+
return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
2727
}

integrations/git_helper_for_declarative_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func allowLFSFilters() []string {
7676
return filteredLFSGlobalArgs[:j]
7777
}
7878

79-
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
79+
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
8080
if len(prepare) == 0 || prepare[0] {
8181
defer prepareTestEnv(t, 1)()
8282
}
@@ -108,6 +108,12 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
108108
callback(t, u)
109109
}
110110

111+
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
112+
onGiteaRunTB(t, func(t testing.TB, u *url.URL) {
113+
callback(t.(*testing.T), u)
114+
}, prepare...)
115+
}
116+
111117
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
112118
return func(t *testing.T) {
113119
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{}))

0 commit comments

Comments
 (0)