From 39879fa868bdaac111711ec40159028ffbdd7469 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 6 Sep 2023 17:51:15 +0300 Subject: [PATCH] [#668] shard/test: Add dontRelease options Most of the time we would like to close shard with minor exceptions. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/shard/gc_test.go | 8 -------- pkg/local_object_storage/shard/range_test.go | 1 - pkg/local_object_storage/shard/shard_test.go | 9 ++++++--- pkg/local_object_storage/shard/shutdown_test.go | 3 +-- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index d6a7e39e..4f19db87 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -27,10 +27,6 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) { sh := newCustomShard(t, false, shardOptions{metaOptions: []meta.Option{meta.WithEpochState(epoch)}}) - t.Cleanup(func() { - releaseShard(sh, t) - }) - cnr := cidtest.ID() 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)}}) - t.Cleanup(func() { - releaseShard(sh, t) - }) - lock := testutil.GenerateObjectWithCID(cnr) lock.SetType(objectSDK.TypeLock) lock.SetAttributes(lockExpirationAttr) diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index 77a20966..a8bc8330 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -97,7 +97,6 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { }), }, }) - defer releaseShard(sh, t) for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 33560407..eb2aba58 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -32,15 +32,14 @@ func (s epochState) CurrentEpoch() uint64 { type shardOptions struct { rootPath string + dontRelease bool wcOpts writecacheconfig.Options bsOpts []blobstor.Option metaOptions []meta.Option } func newShard(t testing.TB, enableWriteCache bool) *Shard { - sh := newCustomShard(t, enableWriteCache, shardOptions{}) - t.Cleanup(func() { releaseShard(sh, t) }) - return sh + return newCustomShard(t, enableWriteCache, shardOptions{}) } 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.Init(context.Background())) + if !o.dontRelease { + t.Cleanup(func() { releaseShard(sh, t) }) + } + return sh } diff --git a/pkg/local_object_storage/shard/shutdown_test.go b/pkg/local_object_storage/shard/shutdown_test.go index 6cfa5fb6..163c3a4a 100644 --- a/pkg/local_object_storage/shard/shutdown_test.go +++ b/pkg/local_object_storage/shard/shutdown_test.go @@ -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 for i := range objects { @@ -59,7 +59,6 @@ func TestWriteCacheObjectLoss(t *testing.T) { require.NoError(t, sh.Close()) sh = newCustomShard(t, true, shardOptions{rootPath: dir, wcOpts: wcOpts}) - defer releaseShard(sh, t) var getPrm GetPrm