From a90a7195d4023a1126e39e798f5a8e8770b8c43e Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Sat, 29 Dec 2018 10:23:56 +0300 Subject: [PATCH] createPopulatedBlock returns the block dir instead of the block (#487) It is easy to forget to close the block returned by createPopulatedBlock which causes failures for windows so instead it returns the block dir and which can be used by OpenBlock explicitly. Signed-off-by: Krasi Georgiev --- block_test.go | 8 +++----- querier_test.go | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/block_test.go b/block_test.go index 03ac006a9e..b74d58a3c6 100644 --- a/block_test.go +++ b/block_test.go @@ -78,8 +78,8 @@ func createEmptyBlock(t *testing.T, dir string, meta *BlockMeta) *Block { } // createPopulatedBlock creates a block with nSeries series, filled with -// samples of the given mint,maxt time range. -func createPopulatedBlock(tb testing.TB, dir string, nSeries int, mint, maxt int64) *Block { +// samples of the given mint,maxt time range and returns its dir. +func createPopulatedBlock(tb testing.TB, dir string, nSeries int, mint, maxt int64) string { head, err := NewHead(nil, nil, nil, 2*60*60*1000) testutil.Ok(tb, err) defer head.Close() @@ -113,7 +113,5 @@ func createPopulatedBlock(tb testing.TB, dir string, nSeries int, mint, maxt int ulid, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime(), nil) testutil.Ok(tb, err) - blk, err := OpenBlock(filepath.Join(dir, ulid.String()), nil) - testutil.Ok(tb, err) - return blk + return filepath.Join(dir, ulid.String()) } diff --git a/querier_test.go b/querier_test.go index 4708185e81..9d038f28e6 100644 --- a/querier_test.go +++ b/querier_test.go @@ -1232,7 +1232,8 @@ func BenchmarkPersistedQueries(b *testing.B) { dir, err := ioutil.TempDir("", "bench_persisted") testutil.Ok(b, err) defer os.RemoveAll(dir) - block := createPopulatedBlock(b, dir, nSeries, 1, int64(nSamples)) + block, err := OpenBlock(createPopulatedBlock(b, dir, nSeries, 1, int64(nSamples)), nil) + testutil.Ok(b, err) defer block.Close() q, err := NewBlockQuerier(block, block.Meta().MinTime, block.Meta().MaxTime)