Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,80 @@ steps:
depends_on:
- build

---
kind: pipeline
name: benching-arm64

platform:
os: linux
arch: arm64

depends_on:
- compliance

trigger:
event:
- push
- tag
- pull_request

services:
- name: pgsql
pull: default
image: postgres:9.5
environment:
POSTGRES_DB: test
POSTGRES_PASSWORD: postgres

- name: ldap
pull: default
image: gitea/test-openldap:latest

steps:
- name: fetch-tags
image: docker:git
commands:
- git fetch --tags --force
when:
event:
exclude:
- pull_request

- name: build
pull: always
image: golang:1.16
commands:
- make backend
environment:
GOPROXY: https://goproxy.cn # proxy.golang.org is blocked in China, this proxy is not
GOSUMDB: sum.golang.org
TAGS: bindata gogit sqlite sqlite_unlock_notify

- name: bench-sqlite
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
commands:
- timeout -s ABRT 40m make bench-sqlite
environment:
GOPROXY: off
TAGS: bindata sqlite sqlite_unlock_notify
TEST_TAGS: sqlite sqlite_unlock_notify
USE_REPO_TEST_DIR: 1
depends_on:
- build

- name: bench-pgsql
image: gitea/test_env:linux-arm64 # https://gitea.com/gitea/test-env
commands:
- timeout -s ABRT 40m make bench-pgsql
environment:
GOPROXY: off
TAGS: bindata gogit
TEST_TAGS: gogit
TEST_LDAP: 1
USE_REPO_TEST_DIR: 1
depends_on:
- build

---
kind: pipeline
name: update_translations
Expand Down Expand Up @@ -484,6 +558,7 @@ trigger:
depends_on:
- testing-amd64
- testing-arm64
- benching-arm64

steps:
- name: fetch-tags
Expand Down Expand Up @@ -579,6 +654,7 @@ trigger:
depends_on:
- testing-arm64
- testing-amd64
- benching-arm64

steps:
- name: fetch-tags
Expand Down Expand Up @@ -692,6 +768,7 @@ platform:
depends_on:
- testing-amd64
- testing-arm64
- benching-arm64

trigger:
ref:
Expand Down Expand Up @@ -789,6 +866,7 @@ platform:
depends_on:
- testing-amd64
- testing-arm64
- benching-arm64

trigger:
ref:
Expand Down Expand Up @@ -915,6 +993,7 @@ trigger:
depends_on:
- testing-amd64
- testing-arm64
- benching-arm64
- release-version
- release-latest
- docker-linux-amd64-release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ _testmain.go

*coverage.out
coverage.all
cpu.out

/modules/options/bindata.go
/modules/options/bindata.go.hash
Expand Down
30 changes: 30 additions & 0 deletions integrations/api_repo_file_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,36 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
}
}

func BenchmarkAPICreateFileSmall(b *testing.B) {
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo

for n := 0; n < b.N; n++ {
treePath := fmt.Sprintf("update/file%d.txt", n)
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
}
})
}

func BenchmarkAPICreateFileMedium(b *testing.B) {
data := make([]byte, 10*1024*1024)

onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo

b.ResetTimer()
for n := 0; n < b.N; n++ {
treePath := fmt.Sprintf("update/file%d.txt", n)
copy(data, treePath)
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
}
})
}

func TestAPICreateFile(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
Expand Down
6 changes: 3 additions & 3 deletions integrations/api_repo_file_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
api "code.gitea.io/gitea/modules/structs"
)

func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName string) (*api.FileResponse, error) {
func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
opts := &repofiles.UpdateRepoFileOptions{
OldBranch: branchName,
TreePath: treePath,
Content: "This is a NEW file",
Content: content,
IsNewFile: true,
Author: nil,
Committer: nil,
Expand All @@ -23,5 +23,5 @@ func createFileInBranch(user *models.User, repo *models.Repository, treePath, br
}

func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
return createFileInBranch(user, repo, treePath, repo.DefaultBranch)
return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
}
62 changes: 27 additions & 35 deletions integrations/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package integrations

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

Expand All @@ -14,16 +14,14 @@ import (
)

func BenchmarkRepo(b *testing.B) {
b.Skip("benchmark broken") // TODO fix
samples := []struct {
url string
name string
skipShort bool
}{
{url: "https://github.com/go-gitea/gitea.git", name: "gitea"},
{url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"},
{url: "https://github.com/moby/moby.git", name: "moby", skipShort: true},
{url: "https://github.com/golang/go.git", name: "go", skipShort: true},
{url: "https://github.com/torvalds/linux.git", name: "linux", skipShort: true},
{url: "https://github.com/go-gitea/test_repo.git", name: "test_repo"},
{url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles", skipShort: true},
}
defer prepareTestEnv(b)()
session := loginUser(b, "user2")
Expand All @@ -34,16 +32,18 @@ func BenchmarkRepo(b *testing.B) {
if testing.Short() && s.skipShort {
b.Skip("skipping test in short mode.")
}
b.Run("Migrate", func(b *testing.B) {
b.Run("Migrate "+s.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "DELETE", "/api/v1/repos/%s/%s", "user2", s.name)
session.MakeRequest(b, req, NoExpectedStatus)
testRepoMigrate(b, session, s.url, s.name)
}
})
b.Run("Access", func(b *testing.B) {
var branches []*api.Branch
b.Run("APIBranchList", func(b *testing.B) {
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "GET", "/api/v1/repos/%s/%s/branches", "user2", s.name)
req := NewRequestf(b, "GET", "/api/v1/repos/%s/%s/branches?page=1&limit=1", "user2", s.name)
resp := session.MakeRequest(b, req, http.StatusOK)
b.StopTimer()
if len(branches) == 0 {
Expand All @@ -52,29 +52,23 @@ func BenchmarkRepo(b *testing.B) {
b.StartTimer()
}
})
branchCount := len(branches)
b.Run("WebViewCommit", func(b *testing.B) {
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "GET", "/%s/%s/commit/%s", "user2", s.name, branches[i%branchCount].Commit.ID)
session.MakeRequest(b, req, http.StatusOK)
}
})

if len(branches) == 1 {
b.Run("WebViewCommit", func(b *testing.B) {
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "GET", "/%s/%s/commit/%s", "user2", s.name, branches[0].Commit.ID)
session.MakeRequest(b, req, http.StatusOK)
}
})
}
})
})
}
}

//StringWithCharset random string (from https://www.calhoun.io/creating-random-strings-in-go/)
func StringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[rand.Intn(len(charset))]
}
return string(b)
}

func BenchmarkRepoBranchCommit(b *testing.B) {
samples := []int64{1, 3, 15, 16}
b.Skip("benchmark broken") // TODO fix
samples := []int64{1, 15, 16}
defer prepareTestEnv(b)()
b.ResetTimer()

Expand All @@ -86,24 +80,22 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
owner := models.AssertExistsAndLoadBean(b, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(b, owner.LoginName)
b.ResetTimer()
b.Run("Create", func(b *testing.B) {
b.Run("CreateBranch", func(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer()
branchName := StringWithCharset(5+rand.Intn(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
b.StartTimer()
testCreateBranch(b, session, owner.LoginName, repo.Name, "branch/master", branchName, http.StatusFound)
testCreateBranch(b, session, owner.LoginName, repo.Name, "branch/master", fmt.Sprintf("new_branch_nr%d", i), http.StatusFound)
}
})
b.Run("Access", func(b *testing.B) {
b.Run("AccessBranchCommits", func(b *testing.B) {
var branches []*api.Branch
req := NewRequestf(b, "GET", "/api/v1/%s/branches", repo.FullName())
resp := session.MakeRequest(b, req, http.StatusOK)
DecodeJSON(b, resp, &branches)
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].Name)
session.MakeRequest(b, req, http.StatusOK)
if len(branches) != 0 {
for i := 0; i < b.N; i++ {
req := NewRequestf(b, "GET", "/api/v1/%s/commits?sha=%s", repo.FullName(), branches[i%len(branches)].Name)
session.MakeRequest(b, req, http.StatusOK)
}
}
})
})
Expand Down
8 changes: 7 additions & 1 deletion integrations/git_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func allowLFSFilters() []string {
return filteredLFSGlobalArgs[:j]
}

func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
if len(prepare) == 0 || prepare[0] {
defer prepareTestEnv(t, 1)()
}
Expand Down Expand Up @@ -108,6 +108,12 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bo
callback(t, u)
}

func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
onGiteaRunTB(t, func(t testing.TB, u *url.URL) {
callback(t.(*testing.T), u)
}, prepare...)
}

func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{}))
Expand Down