diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2018-03-07 14:23:56 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-03-08 19:03:09 +0300 |
commit | 1b45fd2c9a9d0e4bc39516c257115c6186d103b2 (patch) | |
tree | 48aa2d9da46f2941e4c5eec7ffc2f01d46b7b5ea /domains_test.go | |
parent | a7cc1032a847c0eb858d3869a48e9a686845e200 (diff) |
Use godirwak.ReadDirents
Diffstat (limited to 'domains_test.go')
-rw-r--r-- | domains_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/domains_test.go b/domains_test.go index 56901088..36321edb 100644 --- a/domains_test.go +++ b/domains_test.go @@ -2,8 +2,10 @@ package main import ( "crypto/rand" + "fmt" "io/ioutil" "os" + "path/filepath" "testing" "time" @@ -85,3 +87,44 @@ func TestWatchDomains(t *testing.T) { domains = <-update assert.NotNil(t, domains, "if the domains are updated after the timestamp removal") } + +func BenchmarkReadGroups(b *testing.B) { + testRoot, err := ioutil.TempDir("", "gitlab-pages-test") + require.NoError(b, err) + testRoot, err = filepath.EvalSymlinks(testRoot) + require.NoError(b, err) + + defer func(dir string) { + fmt.Printf("cleaning up test directory %s\n", dir) + os.RemoveAll(dir) + }(testRoot) + + defer func(d string) { + rootDir = d + }(rootDir) + rootDir = 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)) + }) +} |