From 1ced0e936f1b8df87ac4690aacf6cd40600d05ab Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 25 Aug 2023 11:43:35 +0300 Subject: [PATCH 1/2] [#637] shard/test: Fix data race Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/shard/metrics_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index 60adc0724..91e158b04 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -28,13 +28,17 @@ type metricsStore struct { errCounter int64 } -func (m metricsStore) SetShardID(_ string) {} +func (m *metricsStore) SetShardID(_ string) {} -func (m metricsStore) SetObjectCounter(objectType string, v uint64) { +func (m *metricsStore) SetObjectCounter(objectType string, v uint64) { + m.mtx.Lock() + defer m.mtx.Unlock() m.objCounters[objectType] = v } -func (m metricsStore) AddToObjectCounter(objectType string, delta int) { +func (m *metricsStore) AddToObjectCounter(objectType string, delta int) { + m.mtx.Lock() + defer m.mtx.Unlock() switch { case delta > 0: m.objCounters[objectType] += uint64(delta) -- 2.45.2 From 1f0b736137516ef9f96db534745bc00e1fa5f373 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 25 Aug 2023 12:04:34 +0300 Subject: [PATCH 2/2] [#649] shard/test: Increase GC remover interval This was set in #348 to speed up tests. It seems 100ms doesn't increase overall test time, but it reduces the amount of logs by 100x factor. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/shard/delete_test.go | 13 +++++++++---- pkg/local_object_storage/shard/shard_test.go | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index aba204f36..bfafcdc74 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -3,6 +3,7 @@ package shard_test import ( "context" "testing" + "time" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" @@ -56,8 +57,10 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { _, err = sh.Delete(context.TODO(), delPrm) require.NoError(t, err) - _, err = sh.Get(context.Background(), getPrm) - require.True(t, client.IsErrObjectNotFound(err)) + require.Eventually(t, func() bool { + _, err = sh.Get(context.Background(), getPrm) + return client.IsErrObjectNotFound(err) + }, time.Second, 50*time.Millisecond) }) t.Run("small object", func(t *testing.T) { @@ -80,7 +83,9 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { _, err = sh.Delete(context.Background(), delPrm) require.NoError(t, err) - _, err = sh.Get(context.Background(), getPrm) - require.True(t, client.IsErrObjectNotFound(err)) + require.Eventually(t, func() bool { + _, err = sh.Get(context.Background(), getPrm) + return client.IsErrObjectNotFound(err) + }, time.Second, 50*time.Millisecond) }) } diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 1083bf014..6337b0b6e 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -101,7 +101,7 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts require.NoError(t, err) return pool }), - shard.WithGCRemoverSleepInterval(1 * time.Millisecond), + shard.WithGCRemoverSleepInterval(100 * time.Millisecond), } sh = shard.New(opts...) -- 2.45.2