forked from TrueCloudLab/frostfs-node
[#321] shard/test: Parallelize TestShard_List
``` go test -count=1 -run TestShard_List -race . Before: 2.492s After: 0.109s ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
47b0ec33c3
commit
969bfb603f
1 changed files with 34 additions and 23 deletions
|
@ -2,6 +2,7 @@ package shard_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||||
|
@ -9,22 +10,21 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShard_List(t *testing.T) {
|
func TestShard_List(t *testing.T) {
|
||||||
sh := newShard(t, false)
|
|
||||||
shWC := newShard(t, true)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
releaseShard(sh, t)
|
|
||||||
releaseShard(shWC, t)
|
|
||||||
}()
|
|
||||||
|
|
||||||
t.Run("without write cache", func(t *testing.T) {
|
t.Run("without write cache", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
sh := newShard(t, false)
|
||||||
|
defer releaseShard(sh, t)
|
||||||
testShardList(t, sh)
|
testShardList(t, sh)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("with write cache", func(t *testing.T) {
|
t.Run("with write cache", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
shWC := newShard(t, true)
|
||||||
|
defer releaseShard(shWC, t)
|
||||||
testShardList(t, shWC)
|
testShardList(t, shWC)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,17 @@ func testShardList(t *testing.T, sh *shard.Shard) {
|
||||||
const C = 10
|
const C = 10
|
||||||
const N = 5
|
const N = 5
|
||||||
|
|
||||||
|
var mtx sync.Mutex
|
||||||
objs := make(map[string]int)
|
objs := make(map[string]int)
|
||||||
var putPrm shard.PutPrm
|
|
||||||
|
|
||||||
|
var errG errgroup.Group
|
||||||
|
errG.SetLimit(C * N)
|
||||||
for i := 0; i < C; i++ {
|
for i := 0; i < C; i++ {
|
||||||
|
errG.Go(func() error {
|
||||||
cnr := cidtest.ID()
|
cnr := cidtest.ID()
|
||||||
|
|
||||||
for j := 0; j < N; j++ {
|
for j := 0; j < N; j++ {
|
||||||
|
errG.Go(func() error {
|
||||||
obj := testutil.GenerateObjectWithCID(cnr)
|
obj := testutil.GenerateObjectWithCID(cnr)
|
||||||
testutil.AddPayload(obj, 1<<2)
|
testutil.AddPayload(obj, 1<<2)
|
||||||
|
|
||||||
|
@ -49,14 +53,21 @@ func testShardList(t *testing.T, sh *shard.Shard) {
|
||||||
obj.SetParentID(idParent)
|
obj.SetParentID(idParent)
|
||||||
obj.SetParent(parent)
|
obj.SetParent(parent)
|
||||||
|
|
||||||
|
mtx.Lock()
|
||||||
objs[object.AddressOf(obj).EncodeToString()] = 0
|
objs[object.AddressOf(obj).EncodeToString()] = 0
|
||||||
|
mtx.Unlock()
|
||||||
|
|
||||||
|
var putPrm shard.PutPrm
|
||||||
putPrm.SetObject(obj)
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
require.NoError(t, err)
|
return err
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
require.NoError(t, errG.Wait())
|
||||||
|
|
||||||
res, err := sh.List()
|
res, err := sh.List()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue