Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-03-08 19:31:41 +0300
committerNick Thomas <nick@gitlab.com>2018-03-08 19:31:41 +0300
commitb50327ea8cc69ab3bbe0223f4d0112d771343ef0 (patch)
tree55721173d8016133de647be8c03071ecd03ffbed /domains_test.go
parent19fc62d0c32def3c6f4562233e5cdd22fb3e6d03 (diff)
parent0a94a639adf87d0e2ad20eeefc2aaaef6f376701 (diff)
Merge branch 'dirwalk-dirents' into 'master'
Avoid unnecessary stat calls when building domain maps See merge request gitlab-org/gitlab-pages!60
Diffstat (limited to 'domains_test.go')
-rw-r--r--domains_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/domains_test.go b/domains_test.go
index 892128e5..ab59ac0d 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -2,6 +2,7 @@ package main
import (
"crypto/rand"
+ "fmt"
"io/ioutil"
"os"
"testing"
@@ -105,3 +106,43 @@ func recvTimeout(t *testing.T, ch <-chan domains) domains {
return nil
}
}
+
+func BenchmarkReadGroups(b *testing.B) {
+ testRoot, err := ioutil.TempDir("", "gitlab-pages-test")
+ require.NoError(b, err)
+
+ cwd, err := os.Getwd()
+ require.NoError(b, err)
+
+ defer func(oldWd, testWd string) {
+ os.Chdir(oldWd)
+ fmt.Printf("cleaning up test directory %s\n", testWd)
+ os.RemoveAll(testWd)
+ }(cwd, testRoot)
+
+ require.NoError(b, os.Chdir(testRoot))
+
+ nGroups := 10000
+ b.Logf("creating fake domains directory with %d groups", nGroups)
+ for i := 0; i < nGroups; i++ {
+ for j := 0; j < 5; j++ {
+ dir := fmt.Sprintf("%s/group-%d/project-%d", testRoot, i, j)
+ require.NoError(b, os.MkdirAll(dir+"/public", 0755))
+
+ fakeConfig := fmt.Sprintf(`{"Domains":[{"Domain":"foo.%d.%d.example.io","Certificate":"bar","Key":"baz"}]}`, i, j)
+ require.NoError(b, ioutil.WriteFile(dir+"/config.json", []byte(fakeConfig), 0644))
+ }
+ if i%100 == 0 {
+ fmt.Print(".")
+ }
+ }
+
+ b.Run("ReadGroups", func(b *testing.B) {
+ var testDomains domains
+ for i := 0; i < 2; i++ {
+ testDomains = domains(make(map[string]*domain))
+ require.NoError(b, testDomains.ReadGroups("example.com"))
+ }
+ b.Logf("found %d domains", len(testDomains))
+ })
+}