From 5ace1587e608c505ed786b6f22a286219bbf99d0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 23 Oct 2022 16:23:44 +0300 Subject: [PATCH] lib/storage: re-use newTestStorage() instead of manually initializing Storage mock This is a follow-up for d2d30581a0ab7470ec2baae7b7d299a6cedb1aed --- lib/storage/merge_test.go | 6 ++---- lib/storage/merge_timing_test.go | 3 +-- lib/storage/partition_search_test.go | 3 +-- lib/storage/table_search_test.go | 3 +-- lib/storage/table_search_timing_test.go | 6 ++---- lib/storage/table_test.go | 6 ++---- lib/storage/table_timing_test.go | 3 +-- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/storage/merge_test.go b/lib/storage/merge_test.go index a329340bf..189935c41 100644 --- a/lib/storage/merge_test.go +++ b/lib/storage/merge_test.go @@ -366,8 +366,7 @@ func TestMergeForciblyStop(t *testing.T) { var rowsMerged, rowsDeleted uint64 close(ch) - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() 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) } @@ -387,8 +386,7 @@ func testMergeBlockStreams(t *testing.T, bsrs []*blockStreamReader, expectedBloc var bsw blockStreamWriter bsw.InitFromInmemoryPart(&mp) - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var rowsMerged, rowsDeleted uint64 if err := mergeBlockStreams(&mp.ph, &bsw, bsrs, nil, strg, 0, &rowsMerged, &rowsDeleted); err != nil { t.Fatalf("unexpected error in mergeBlockStreams: %s", err) diff --git a/lib/storage/merge_timing_test.go b/lib/storage/merge_timing_test.go index 5c68bae5e..5cbbe5455 100644 --- a/lib/storage/merge_timing_test.go +++ b/lib/storage/merge_timing_test.go @@ -24,8 +24,7 @@ func BenchmarkMergeBlockStreamsFourSourcesBestCase(b *testing.B) { func benchmarkMergeBlockStreams(b *testing.B, mps []*inmemoryPart, rowsPerLoop int64) { var rowsMerged, rowsDeleted uint64 - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() b.ReportAllocs() b.SetBytes(rowsPerLoop) diff --git a/lib/storage/partition_search_test.go b/lib/storage/partition_search_test.go index 6e4fb62d6..7844a3bef 100644 --- a/lib/storage/partition_search_test.go +++ b/lib/storage/partition_search_test.go @@ -165,8 +165,7 @@ func testPartitionSearchEx(t *testing.T, ptt int64, tr TimeRange, partsCount, ma }) // Create partition from rowss and test search on it. - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() retentionMsecs := timestampFromTime(time.Now()) - ptr.MinTimestamp + 3600*1000 var isReadOnly uint32 pt, err := createPartition(ptt, "./small-table", "./big-table", strg, retentionMsecs, &isReadOnly) diff --git a/lib/storage/table_search_test.go b/lib/storage/table_search_test.go index 7f4bf08c7..5676bfcd3 100644 --- a/lib/storage/table_search_test.go +++ b/lib/storage/table_search_test.go @@ -181,8 +181,7 @@ func testTableSearchEx(t *testing.T, trData, trSearch TimeRange, partitionsCount }) // Create a table from rowss and test search on it. - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var isReadOnly uint32 tb, err := openTable("./test-table", strg, maxRetentionMsecs, &isReadOnly) if err != nil { diff --git a/lib/storage/table_search_timing_test.go b/lib/storage/table_search_timing_test.go index 5c0140176..1308d8ac5 100644 --- a/lib/storage/table_search_timing_test.go +++ b/lib/storage/table_search_timing_test.go @@ -44,8 +44,7 @@ func openBenchTable(b *testing.B, startTimestamp int64, rowsPerInsert, rowsCount createBenchTable(b, path, startTimestamp, rowsPerInsert, rowsCount, tsidsCount) createdBenchTables[path] = true } - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var isReadOnly uint32 tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly) 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) { b.Helper() - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var isReadOnly uint32 tb, err := openTable(path, strg, maxRetentionMsecs, &isReadOnly) if err != nil { diff --git a/lib/storage/table_test.go b/lib/storage/table_test.go index 2a3533a24..7268d45d7 100644 --- a/lib/storage/table_test.go +++ b/lib/storage/table_test.go @@ -17,8 +17,7 @@ func TestTableOpenClose(t *testing.T) { }() // Create a new table - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var isReadOnly uint32 tb, err := openTable(path, strg, retentionMsecs, &isReadOnly) if err != nil { @@ -46,8 +45,7 @@ func TestTableOpenMultipleTimes(t *testing.T) { _ = os.RemoveAll(path) }() - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() var isReadOnly uint32 tb1, err := openTable(path, strg, retentionMsecs, &isReadOnly) if err != nil { diff --git a/lib/storage/table_timing_test.go b/lib/storage/table_timing_test.go index 2b4cd6316..01bae910a 100644 --- a/lib/storage/table_timing_test.go +++ b/lib/storage/table_timing_test.go @@ -45,8 +45,7 @@ func benchmarkTableAddRows(b *testing.B, rowsPerInsert, tsidsCount int) { b.ReportAllocs() b.SetBytes(int64(rowsCountExpected)) tablePath := "./benchmarkTableAddRows" - strg := &Storage{} - strg.setDeletedMetricIDs(nil) + strg := newTestStorage() for i := 0; i < b.N; i++ { var isReadOnly uint32 tb, err := openTable(tablePath, strg, maxRetentionMsecs, &isReadOnly)