lib/storage: re-use newTestStorage() instead of manually initializing Storage mock

This is a follow-up for d2d30581a0
This commit is contained in:
Aliaksandr Valialkin 2022-10-23 16:23:44 +03:00
parent 57ea7a3ee8
commit 5ace1587e6
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
7 changed files with 10 additions and 20 deletions

View file

@ -366,8 +366,7 @@ func TestMergeForciblyStop(t *testing.T) {
var rowsMerged, rowsDeleted uint64 var rowsMerged, rowsDeleted uint64
close(ch) close(ch)
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, ch, strg, 0, &rowsMerged, &rowsDeleted); !errors.Is(err, errForciblyStopped) { if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, ch, strg, 0, &rowsMerged, &rowsDeleted); !errors.Is(err, errForciblyStopped) {
t.Fatalf("unexpected error in mergeBlockStreams: got %v; want %v", err, errForciblyStopped) t.Fatalf("unexpected error in mergeBlockStreams: got %v; want %v", err, errForciblyStopped)
} }
@ -387,8 +386,7 @@ func testMergeBlockStreams(t *testing.T, bsrs []*blockStreamReader, expectedBloc
var bsw blockStreamWriter var bsw blockStreamWriter
bsw.InitFromInmemoryPart(&mp) bsw.InitFromInmemoryPart(&mp)
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var rowsMerged, rowsDeleted uint64 var rowsMerged, rowsDeleted uint64
if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, nil, strg, 0, &rowsMerged, &rowsDeleted); err != nil { if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, nil, strg, 0, &rowsMerged, &rowsDeleted); err != nil {
t.Fatalf("unexpected error in mergeBlockStreams: %s", err) t.Fatalf("unexpected error in mergeBlockStreams: %s", err)

View file

@ -24,8 +24,7 @@ func BenchmarkMergeBlockStreamsFourSourcesBestCase(b *testing.B) {
func benchmarkMergeBlockStreams(b *testing.B, mps []*inmemoryPart, rowsPerLoop int64) { func benchmarkMergeBlockStreams(b *testing.B, mps []*inmemoryPart, rowsPerLoop int64) {
var rowsMerged, rowsDeleted uint64 var rowsMerged, rowsDeleted uint64
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
b.ReportAllocs() b.ReportAllocs()
b.SetBytes(rowsPerLoop) b.SetBytes(rowsPerLoop)

View file

@ -165,8 +165,7 @@ func testPartitionSearchEx(t *testing.T, ptt int64, tr TimeRange, partsCount, ma
}) })
// Create partition from rowss and test search on it. // Create partition from rowss and test search on it.
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
retentionMsecs := timestampFromTime(time.Now()) - ptr.MinTimestamp + 3600*1000 retentionMsecs := timestampFromTime(time.Now()) - ptr.MinTimestamp + 3600*1000
var isReadOnly uint32 var isReadOnly uint32
pt, err := createPartition(ptt, "./small-table", "./big-table", strg, retentionMsecs, &isReadOnly) pt, err := createPartition(ptt, "./small-table", "./big-table", strg, retentionMsecs, &isReadOnly)

View file

@ -181,8 +181,7 @@ func testTableSearchEx(t *testing.T, trData, trSearch TimeRange, partitionsCount
}) })
// Create a table from rowss and test search on it. // Create a table from rowss and test search on it.
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var isReadOnly uint32 var isReadOnly uint32
tb, err := openTable("./test-table", strg, maxRetentionMsecs, &isReadOnly) tb, err := openTable("./test-table", strg, maxRetentionMsecs, &isReadOnly)
if err != nil { if err != nil {

View file

@ -44,8 +44,7 @@ func openBenchTable(b *testing.B, startTimestamp int64, rowsPerInsert, rowsCount
createBenchTable(b, path, startTimestamp, rowsPerInsert, rowsCount, tsidsCount) createBenchTable(b, path, startTimestamp, rowsPerInsert, rowsCount, tsidsCount)
createdBenchTables[path] = true createdBenchTables[path] = true
} }
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var isReadOnly uint32 var isReadOnly uint32
tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly) tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly)
if err != nil { if err != nil {
@ -70,8 +69,7 @@ var createdBenchTables = make(map[string]bool)
func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerInsert, rowsCount, tsidsCount int) { func createBenchTable(b *testing.B, path string, startTimestamp int64, rowsPerInsert, rowsCount, tsidsCount int) {
b.Helper() b.Helper()
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var isReadOnly uint32 var isReadOnly uint32
tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly) tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly)
if err != nil { if err != nil {

View file

@ -17,8 +17,7 @@ func TestTableOpenClose(t *testing.T) {
}() }()
// Create a new table // Create a new table
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var isReadOnly uint32 var isReadOnly uint32
tb, err := openTable(path, strg, retentionMsecs, &isReadOnly) tb, err := openTable(path, strg, retentionMsecs, &isReadOnly)
if err != nil { if err != nil {
@ -46,8 +45,7 @@ func TestTableOpenMultipleTimes(t *testing.T) {
_ = os.RemoveAll(path) _ = os.RemoveAll(path)
}() }()
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
var isReadOnly uint32 var isReadOnly uint32
tb1, err := openTable(path, strg, retentionMsecs, &isReadOnly) tb1, err := openTable(path, strg, retentionMsecs, &isReadOnly)
if err != nil { if err != nil {

View file

@ -45,8 +45,7 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) {
b.ReportAllocs() b.ReportAllocs()
b.SetBytes(int64(rowsCountExpected)) b.SetBytes(int64(rowsCountExpected))
tablePath := "./benchmarkTableAddRows" tablePath := "./benchmarkTableAddRows"
strg := &Storage{} strg := newTestStorage()
strg.setDeletedMetricIDs(nil)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var isReadOnly uint32 var isReadOnly uint32
tb, err := openTable(tablePath, strg, maxRetentionMsecs, &isReadOnly) tb, err := openTable(tablePath, strg, maxRetentionMsecs, &isReadOnly)