Dmitrii Stepanov
8d18fa159e
All checks were successful
DCO action / DCO (pull_request) Successful in 1m28s
Vulncheck / Vulncheck (pull_request) Successful in 3m55s
Tests and linters / Staticcheck (pull_request) Successful in 4m15s
Build / Build Components (1.21) (pull_request) Successful in 4m40s
Build / Build Components (1.20) (pull_request) Successful in 4m54s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m32s
Tests and linters / Lint (pull_request) Successful in 5m59s
Tests and linters / Tests (1.21) (pull_request) Successful in 6m59s
Tests and linters / Tests with -race (pull_request) Successful in 6m57s
Allow to disable background flusher for testing purposes. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package writecachebadger
|
|
|
|
import (
|
|
"path/filepath"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachetest"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
"github.com/dgraph-io/badger/v4"
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func TestFlush(t *testing.T) {
|
|
testlogger := test.NewLogger(t, true)
|
|
|
|
createCacheFn := func(t *testing.T, smallSize uint64, mb *meta.DB, bs writecache.MainStorage, opts ...Option) writecache.Cache {
|
|
return New(
|
|
append([]Option{
|
|
WithLogger(test.NewLogger(t, true)),
|
|
WithPath(filepath.Join(t.TempDir(), "writecache")),
|
|
WithMetabase(mb),
|
|
WithBlobstor(bs),
|
|
WithGCInterval(1 * time.Second),
|
|
WithDisableBackgroundFlush(),
|
|
}, opts...)...)
|
|
}
|
|
|
|
errCountOpt := func() (Option, *atomic.Uint32) {
|
|
cnt := &atomic.Uint32{}
|
|
return WithReportErrorFunc(func(msg string, err error) {
|
|
cnt.Add(1)
|
|
testlogger.Warn(msg, zap.Uint32("error_count", cnt.Load()), zap.Error(err))
|
|
}), cnt
|
|
}
|
|
|
|
failures := []writecachetest.TestFailureInjector[Option]{
|
|
{
|
|
Desc: "db, invalid address",
|
|
InjectFn: func(t *testing.T, wc writecache.Cache) {
|
|
c := wc.(*cache)
|
|
obj := testutil.GenerateObject()
|
|
data, err := obj.Marshal()
|
|
require.NoError(t, err)
|
|
require.NoError(t, c.db.Update(func(tx *badger.Txn) error {
|
|
return tx.Set([]byte{1, 2, 3}, data)
|
|
}))
|
|
},
|
|
},
|
|
{
|
|
Desc: "db, invalid object",
|
|
InjectFn: func(t *testing.T, wc writecache.Cache) {
|
|
c := wc.(*cache)
|
|
key := addr2key(oidtest.Address())
|
|
require.NoError(t, c.db.Update(func(tx *badger.Txn) error {
|
|
return tx.Set(key[:], []byte{1, 2, 3})
|
|
}))
|
|
},
|
|
},
|
|
}
|
|
|
|
writecachetest.TestFlush(t, createCacheFn, errCountOpt, failures...)
|
|
}
|