[#637] shard: Fix data race in tests #649
3 changed files with 17 additions and 8 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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...)
|
||||
|
|
Loading…
Reference in a new issue