[#668] shard/test: Add dontRelease options

Most of the time we would like to close shard with minor exceptions.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-09-06 17:51:15 +03:00 committed by Evgenii Stratonikov
parent c661ba1312
commit 39879fa868
4 changed files with 7 additions and 14 deletions

View file

@ -27,10 +27,6 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) {
sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}}) sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
t.Cleanup(func() {
releaseShard(sh, t)
})
cnr := cidtest.ID() cnr := cidtest.ID()
var objExpirationAttr objectSDK.Attribute var objExpirationAttr objectSDK.Attribute
@ -124,10 +120,6 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) {
sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}}) sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}})
t.Cleanup(func() {
releaseShard(sh, t)
})
lock := testutil.GenerateObjectWithCID(cnr) lock := testutil.GenerateObjectWithCID(cnr)
lock.SetType(objectSDK.TypeLock) lock.SetType(objectSDK.TypeLock)
lock.SetAttributes(lockExpirationAttr) lock.SetAttributes(lockExpirationAttr)

View file

@ -97,7 +97,6 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) {
}), }),
}, },
}) })
defer releaseShard(sh, t)
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {

View file

@ -32,15 +32,14 @@ func (s epochState) CurrentEpoch() uint64 {
type shardOptions struct { type shardOptions struct {
rootPath string rootPath string
dontRelease bool
wcOpts writecacheconfig.Options wcOpts writecacheconfig.Options
bsOpts []blobstor.Option bsOpts []blobstor.Option
metaOptions []meta.Option metaOptions []meta.Option
} }
func newShard(t testing.TB, enableWriteCache bool) *Shard { func newShard(t testing.TB, enableWriteCache bool) *Shard {
sh := newCustomShard(t, enableWriteCache, shardOptions{}) return newCustomShard(t, enableWriteCache, shardOptions{})
t.Cleanup(func() { releaseShard(sh, t) })
return sh
} }
func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard { func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard {
@ -121,6 +120,10 @@ func newCustomShard(t testing.TB, enableWriteCache bool, o shardOptions) *Shard
require.NoError(t, sh.Open()) require.NoError(t, sh.Open())
require.NoError(t, sh.Init(context.Background())) require.NoError(t, sh.Init(context.Background()))
if !o.dontRelease {
t.Cleanup(func() { releaseShard(sh, t) })
}
return sh return sh
} }

View file

@ -43,7 +43,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
}, },
} }
sh := newCustomShard(t, true, shardOptions{rootPath: dir, wcOpts: wcOpts}) sh := newCustomShard(t, true, shardOptions{dontRelease: true, rootPath: dir, wcOpts: wcOpts})
var errG errgroup.Group var errG errgroup.Group
for i := range objects { for i := range objects {
@ -59,7 +59,6 @@ func TestWriteCacheObjectLoss(t *testing.T) {
require.NoError(t, sh.Close()) require.NoError(t, sh.Close())
sh = newCustomShard(t, true, shardOptions{rootPath: dir, wcOpts: wcOpts}) sh = newCustomShard(t, true, shardOptions{rootPath: dir, wcOpts: wcOpts})
defer releaseShard(sh, t)
var getPrm GetPrm var getPrm GetPrm