From 1ced0e936f1b8df87ac4690aacf6cd40600d05ab Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 25 Aug 2023 11:43:35 +0300 Subject: [PATCH] [#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)