|
6 | 6 | "time"
|
7 | 7 |
|
8 | 8 | "github.com/prometheus/common/model"
|
| 9 | + "github.com/stretchr/testify/require" |
9 | 10 |
|
10 | 11 | "github.com/cortexproject/cortex/pkg/chunk"
|
11 | 12 | promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding"
|
@@ -55,6 +56,22 @@ func BenchmarkNewChunkMergeIterator_CreateAndIterate(b *testing.B) {
|
55 | 56 | }
|
56 | 57 | }
|
57 | 58 |
|
| 59 | +func TestSeekCorrectlyDealWithSinglePointChunks(t *testing.T) { |
| 60 | + chunkOne := mkChunk(t, model.Time(1*step/time.Millisecond), 1, promchunk.PrometheusXorChunk) |
| 61 | + chunkTwo := mkChunk(t, model.Time(10*step/time.Millisecond), 1, promchunk.PrometheusXorChunk) |
| 62 | + chunks := []chunk.Chunk{chunkOne, chunkTwo} |
| 63 | + |
| 64 | + sut := NewChunkMergeIterator(chunks, 0, 0) |
| 65 | + |
| 66 | + // Following calls mimics Prometheus's query engine behaviour for VectorSelector. |
| 67 | + require.True(t, sut.Next()) |
| 68 | + require.True(t, sut.Seek(0)) |
| 69 | + |
| 70 | + actual, val := sut.At() |
| 71 | + require.Equal(t, float64(1*time.Second/time.Millisecond), val) // since mkChunk use ts as value. |
| 72 | + require.Equal(t, int64(1*time.Second/time.Millisecond), actual) |
| 73 | +} |
| 74 | + |
58 | 75 | func createChunks(b *testing.B, numChunks, numSamplesPerChunk, duplicationFactor int, enc promchunk.Encoding) []chunk.Chunk {
|
59 | 76 | result := make([]chunk.Chunk, 0, numChunks)
|
60 | 77 |
|
|
0 commit comments