From 4b0d43a6f0fb02567b0d0fe3b2c671f39ab9d4e5 Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Fri, 30 Aug 2024 14:02:57 +0300 Subject: [PATCH] [#1320] test: Fix TestGCDropsObjectInhumedFromWritecache flaky test The `TestGCDropsObjectInhumedFromWritecache` test was flaky because a running asynchronous rebuild operation prevented GC from deleting the object. A test-only shard option `WithDisabledRebuild` has been added to fix this. Signed-off-by: Aleksey Savchuk --- pkg/local_object_storage/shard/control.go | 4 ++-- pkg/local_object_storage/shard/gc_test.go | 2 +- pkg/local_object_storage/shard/shard.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index 1626d5804..6efe4ec37 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -130,7 +130,7 @@ func (s *Shard) Init(ctx context.Context) error { s.gc.init(ctx) s.rb = newRebuilder(s.rebuildLimiter) - if !m.NoMetabase() { + if !m.NoMetabase() && !s.rebuildDisabled { s.rb.Start(ctx, s.blobStor, s.metaBase, s.log) } s.writecacheSealCancel.Store(dummyCancel) @@ -398,7 +398,7 @@ func (s *Shard) Reload(ctx context.Context, opts ...Option) error { defer unlock() s.rb.Stop(s.log) - if !s.info.Mode.NoMetabase() { + if !s.info.Mode.NoMetabase() && !s.rebuildDisabled { defer func() { s.rb.Start(ctx, s.blobStor, s.metaBase, s.log) }() diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index 90958cd35..1c0ef1c2e 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -187,7 +187,7 @@ func TestGCDropsObjectInhumedFromWritecache(t *testing.T) { func testGCDropsObjectInhumedFromWritecache(t *testing.T, flushbeforeInhume bool) { sh := newCustomShard(t, true, shardOptions{ - additionalShardOptions: []Option{WithDisabledGC()}, + additionalShardOptions: []Option{WithDisabledGC(), WithDisabledRebuild()}, wcOpts: []writecache.Option{writecache.WithDisableBackgroundFlush()}, }) defer func() { require.NoError(t, sh.Close()) }() diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 93f5354a7..d11bcc36b 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -139,6 +139,8 @@ type cfg struct { reportErrorFunc func(selfID string, message string, err error) rebuildLimiter RebuildWorkerLimiter + + rebuildDisabled bool } func defaultCfg() *cfg { @@ -410,6 +412,14 @@ func WithZeroCountCallback(cb EmptyContainersCallback) Option { } } +// WithDisabledRebuild returns an option to disable a shard rebuild. +// For testing purposes only. +func WithDisabledRebuild() Option { + return func(c *cfg) { + c.rebuildDisabled = true + } +} + func (s *Shard) fillInfo() { s.cfg.info.MetaBaseInfo = s.metaBase.DumpInfo() s.cfg.info.BlobStorInfo = s.blobStor.DumpInfo()