From 7a12d4588af017e495bcc6f5122a9e25e493dfb9 Mon Sep 17 00:00:00 2001 From: naivewong <867245430@qq.com> Date: Thu, 18 Apr 2019 21:11:39 +0800 Subject: [PATCH] Avoid potential collision of createIdxChkReaders in querier_test.go (#585) * Make chink ref monotonically increasing number in the `createIdxChkReaders` test func. Signed-off-by: naivewong <867245430@qq.com> --- querier_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/querier_test.go b/querier_test.go index a9bb0086..3b700328 100644 --- a/querier_test.go +++ b/querier_test.go @@ -206,13 +206,11 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i blockMint := int64(math.MaxInt64) blockMaxt := int64(math.MinInt64) + var chunkRef uint64 for i, s := range tc { i = i + 1 // 0 is not a valid posting. metas := make([]chunks.Meta, 0, len(s.chunks)) for _, chk := range s.chunks { - // Collisions can be there, but for tests, its fine. - ref := rand.Uint64() - if chk[0].t < blockMint { blockMint = chk[0].t } @@ -223,7 +221,7 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i metas = append(metas, chunks.Meta{ MinTime: chk[0].t, MaxTime: chk[len(chk)-1].t, - Ref: ref, + Ref: chunkRef, }) chunk := chunkenc.NewXORChunk() @@ -231,7 +229,8 @@ func createIdxChkReaders(tc []seriesSamples) (IndexReader, ChunkReader, int64, i for _, smpl := range chk { app.Append(smpl.t, smpl.v) } - chkReader[ref] = chunk + chkReader[chunkRef] = chunk + chunkRef += 1 } ls := labels.FromMap(s.lset)