[#236] blobstor/test: Reduce test descriptions
I tried to add 4 more tests and suddenly, it became harder to navigate in code. Move directory creation in a common function. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
6bf11f7cca
commit
c85a0bc866
1 changed files with 35 additions and 49 deletions
|
@ -13,60 +13,65 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type storage struct {
|
||||||
|
desc string
|
||||||
|
create func(string) common.Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s storage) open(b *testing.B) common.Storage {
|
||||||
|
dir, err := os.MkdirTemp(os.TempDir(), s.desc)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("creating %s root path: %v", s.desc, err)
|
||||||
|
}
|
||||||
|
st := s.create(dir)
|
||||||
|
|
||||||
|
require.NoError(b, st.Open(false))
|
||||||
|
require.NoError(b, st.Init())
|
||||||
|
|
||||||
|
b.Cleanup(func() {
|
||||||
|
require.NoError(b, st.Close())
|
||||||
|
require.NoError(b, os.RemoveAll(dir))
|
||||||
|
})
|
||||||
|
|
||||||
|
return st
|
||||||
|
}
|
||||||
|
|
||||||
// The storages to benchmark. Each storage has a description and a function which returns the actual
|
// The storages to benchmark. Each storage has a description and a function which returns the actual
|
||||||
// storage along with a cleanup function.
|
// storage along with a cleanup function.
|
||||||
var storages = []struct {
|
var storages = []storage{
|
||||||
desc string
|
|
||||||
create func(*testing.B) (common.Storage, func())
|
|
||||||
}{
|
|
||||||
{
|
{
|
||||||
desc: "memstore",
|
desc: "memstore",
|
||||||
create: func(*testing.B) (common.Storage, func()) {
|
create: func(string) common.Storage {
|
||||||
return memstore.New(), func() {}
|
return memstore.New()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "fstree_nosync",
|
desc: "fstree_nosync",
|
||||||
create: func(b *testing.B) (common.Storage, func()) {
|
create: func(dir string) common.Storage {
|
||||||
dir, err := os.MkdirTemp(os.TempDir(), "fstree_nosync")
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("creating fstree_nosync root path: %v", err)
|
|
||||||
}
|
|
||||||
cleanup := func() { os.RemoveAll(dir) }
|
|
||||||
return fstree.New(
|
return fstree.New(
|
||||||
fstree.WithPath(dir),
|
fstree.WithPath(dir),
|
||||||
fstree.WithDepth(2),
|
fstree.WithDepth(2),
|
||||||
fstree.WithDirNameLen(2),
|
fstree.WithDirNameLen(2),
|
||||||
fstree.WithNoSync(true),
|
fstree.WithNoSync(true),
|
||||||
), cleanup
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "fstree",
|
desc: "fstree",
|
||||||
create: func(b *testing.B) (common.Storage, func()) {
|
create: func(dir string) common.Storage {
|
||||||
dir, err := os.MkdirTemp(os.TempDir(), "fstree")
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("creating fstree root path: %v", err)
|
|
||||||
}
|
|
||||||
cleanup := func() { os.RemoveAll(dir) }
|
|
||||||
return fstree.New(
|
return fstree.New(
|
||||||
fstree.WithPath(dir),
|
fstree.WithPath(dir),
|
||||||
fstree.WithDepth(2),
|
fstree.WithDepth(2),
|
||||||
fstree.WithDirNameLen(2),
|
fstree.WithDirNameLen(2),
|
||||||
), cleanup
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "blobovniczatree",
|
desc: "blobovniczatree",
|
||||||
create: func(b *testing.B) (common.Storage, func()) {
|
create: func(dir string) common.Storage {
|
||||||
dir, err := os.MkdirTemp(os.TempDir(), "blobovniczatree")
|
|
||||||
if err != nil {
|
|
||||||
b.Fatalf("creating blobovniczatree root path: %v", err)
|
|
||||||
}
|
|
||||||
cleanup := func() { os.RemoveAll(dir) }
|
|
||||||
return blobovniczatree.NewBlobovniczaTree(
|
return blobovniczatree.NewBlobovniczaTree(
|
||||||
blobovniczatree.WithRootPath(dir),
|
blobovniczatree.WithRootPath(dir),
|
||||||
), cleanup
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -95,10 +100,7 @@ func BenchmarkSubstorageReadPerf(b *testing.B) {
|
||||||
for _, stEntry := range storages {
|
for _, stEntry := range storages {
|
||||||
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
||||||
objGen := tt.objGen()
|
objGen := tt.objGen()
|
||||||
st, cleanup := stEntry.create(b)
|
st := stEntry.open(b)
|
||||||
|
|
||||||
require.NoError(b, st.Open(false))
|
|
||||||
require.NoError(b, st.Init())
|
|
||||||
|
|
||||||
// Fill database
|
// Fill database
|
||||||
for i := 0; i < tt.size; i++ {
|
for i := 0; i < tt.size; i++ {
|
||||||
|
@ -123,9 +125,6 @@ func BenchmarkSubstorageReadPerf(b *testing.B) {
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
require.NoError(b, st.Close())
|
|
||||||
cleanup()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,10 +149,7 @@ func BenchmarkSubstorageWritePerf(b *testing.B) {
|
||||||
for _, stEntry := range storages {
|
for _, stEntry := range storages {
|
||||||
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, genEntry.desc), func(b *testing.B) {
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, genEntry.desc), func(b *testing.B) {
|
||||||
gen := genEntry.create()
|
gen := genEntry.create()
|
||||||
st, cleanup := stEntry.create(b)
|
st := stEntry.open(b)
|
||||||
|
|
||||||
require.NoError(b, st.Open(false))
|
|
||||||
require.NoError(b, st.Init())
|
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
@ -170,9 +166,6 @@ func BenchmarkSubstorageWritePerf(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
require.NoError(b, st.Close())
|
|
||||||
cleanup()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,10 +187,7 @@ func BenchmarkSubstorageIteratePerf(b *testing.B) {
|
||||||
for _, stEntry := range storages {
|
for _, stEntry := range storages {
|
||||||
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
b.Run(fmt.Sprintf("%s-%s", stEntry.desc, tt.desc), func(b *testing.B) {
|
||||||
objGen := tt.objGen()
|
objGen := tt.objGen()
|
||||||
st, cleanup := stEntry.create(b)
|
st := stEntry.open(b)
|
||||||
|
|
||||||
require.NoError(b, st.Open(false))
|
|
||||||
require.NoError(b, st.Init())
|
|
||||||
|
|
||||||
// Fill database
|
// Fill database
|
||||||
for i := 0; i < tt.size; i++ {
|
for i := 0; i < tt.size; i++ {
|
||||||
|
@ -224,10 +214,6 @@ func BenchmarkSubstorageIteratePerf(b *testing.B) {
|
||||||
})
|
})
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
require.Equal(b, tt.size, cnt)
|
require.Equal(b, tt.size, cnt)
|
||||||
b.StopTimer()
|
|
||||||
|
|
||||||
require.NoError(b, st.Close())
|
|
||||||
cleanup()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue