Skip to content

Commit 4694b2f

Browse files
committed
Apply recommendations of @ethantkoenig
1 parent 77e169a commit 4694b2f

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

integrations/benchmarks_test.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package integrations
66

77
import (
8-
"fmt"
98
"math/rand"
109
"net/http"
1110
"testing"
@@ -54,7 +53,7 @@ func BenchmarkRepo(b *testing.B) {
5453
}
5554
})
5655
branchCount := len(branches)
57-
b.Run("WebBranchCommit", func(b *testing.B) {
56+
b.Run("WebViewCommit", func(b *testing.B) {
5857
for i := 0; i < b.N; i++ {
5958
req := NewRequestf(b, "GET", "/%s/%s/commit/%s", "user2", s.name, branches[i%branchCount].Commit.ID)
6059
session.MakeRequest(b, req, http.StatusOK)
@@ -75,46 +74,35 @@ func StringWithCharset(length int, charset string) string {
7574
}
7675

7776
func BenchmarkRepoBranchCommit(b *testing.B) {
78-
samples := []struct {
79-
repoID int64
80-
repo *models.Repository
81-
owner *models.User
82-
}{
83-
{repoID: 1},
84-
{repoID: 3},
85-
{repoID: 15},
86-
{repoID: 16},
87-
}
88-
77+
samples := []int64{1, 3, 15, 16}
8978
prepareTestEnv(b)
90-
for i, s := range samples {
91-
samples[i].repo = models.AssertExistsAndLoadBean(b, &models.Repository{ID: s.repoID}).(*models.Repository)
92-
samples[i].owner = models.AssertExistsAndLoadBean(b, &models.User{ID: samples[i].repo.OwnerID}).(*models.User)
93-
}
9479
b.ResetTimer()
95-
for _, s := range samples {
96-
b.Run(s.repo.Name, func(b *testing.B) {
97-
session := loginUser(b, s.owner.LoginName)
80+
81+
for _, repoID := range samples {
82+
b.StopTimer()
83+
repo := models.AssertExistsAndLoadBean(b, &models.Repository{ID: repoID}).(*models.Repository)
84+
b.StartTimer()
85+
b.Run(repo.Name, func(b *testing.B) {
86+
owner := models.AssertExistsAndLoadBean(b, &models.User{ID: repo.OwnerID}).(*models.User)
87+
session := loginUser(b, owner.LoginName)
9888
b.ResetTimer()
9989
b.Run("Create", func(b *testing.B) {
10090
for i := 0; i < b.N; i++ {
10191
b.StopTimer()
102-
branchName := StringWithCharset(5+rand.Intn(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/")
103-
fmt.Println(branchName)
92+
branchName := StringWithCharset(5+rand.Intn(10), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
10493
b.StartTimer()
105-
testCreateBranch(b, session, s.owner.LoginName, s.repo.Name, "branch/master", branchName, http.StatusFound)
94+
testCreateBranch(b, session, owner.LoginName, repo.Name, "branch/master", branchName, http.StatusFound)
10695
}
10796
})
10897
b.Run("Access", func(b *testing.B) {
10998
var branches []*api.Branch
110-
req := NewRequestf(b, "GET", "/api/v1/%s/branches", s.repo.FullName())
99+
req := NewRequestf(b, "GET", "/api/v1/%s/branches", repo.FullName())
111100
resp := session.MakeRequest(b, req, http.StatusOK)
112101
DecodeJSON(b, resp, &branches)
113-
fmt.Println(branches)
114102
branchCount := len(branches)
115103
b.ResetTimer() //We measure from here
116104
for i := 0; i < b.N; i++ {
117-
req := NewRequestf(b, "GET", "/%s/%s/commits/%s", s.owner.Name, s.repo.Name, branches[i%branchCount])
105+
req := NewRequestf(b, "GET", "/%s/%s/commits/%s", owner.Name, repo.Name, branches[i%branchCount])
118106
session.MakeRequest(b, req, http.StatusOK)
119107
}
120108
})

0 commit comments

Comments
 (0)