MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestStream

Function TestStream

pkg/querier/batch/stream_test.go:14–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestStream(t *testing.T) {
15 t.Parallel()
16 forEncodings(t, func(t *testing.T, enc encoding.Encoding) {
17 for i, tc := range []struct {
18 input1, input2 []promchunk.Batch
19 output batchStream
20 }{
21 {
22 input1: []promchunk.Batch{mkBatch(0, enc)},
23 output: []promchunk.Batch{mkBatch(0, enc)},
24 },
25
26 {
27 input1: []promchunk.Batch{mkBatch(0, enc)},
28 input2: []promchunk.Batch{mkBatch(0, enc)},
29 output: []promchunk.Batch{mkBatch(0, enc)},
30 },
31
32 {
33 input1: []promchunk.Batch{mkBatch(0, enc)},
34 input2: []promchunk.Batch{mkBatch(promchunk.BatchSize, enc)},
35 output: []promchunk.Batch{mkBatch(0, enc), mkBatch(promchunk.BatchSize, enc)},
36 },
37
38 {
39 input1: []promchunk.Batch{mkBatch(0, enc), mkBatch(promchunk.BatchSize, enc)},
40 input2: []promchunk.Batch{mkBatch(promchunk.BatchSize/2, enc), mkBatch(2*promchunk.BatchSize, enc)},
41 output: []promchunk.Batch{mkBatch(0, enc), mkBatch(promchunk.BatchSize, enc), mkBatch(2*promchunk.BatchSize, enc)},
42 },
43
44 {
45 input1: []promchunk.Batch{mkBatch(promchunk.BatchSize/2, enc), mkBatch(3*promchunk.BatchSize/2, enc), mkBatch(5*promchunk.BatchSize/2, enc)},
46 input2: []promchunk.Batch{mkBatch(0, enc), mkBatch(promchunk.BatchSize, enc), mkBatch(3*promchunk.BatchSize, enc)},
47 output: []promchunk.Batch{mkBatch(0, enc), mkBatch(promchunk.BatchSize, enc), mkBatch(2*promchunk.BatchSize, enc), mkBatch(3*promchunk.BatchSize, enc)},
48 },
49 } {
50 t.Run(strconv.Itoa(i), func(t *testing.T) {
51 t.Parallel()
52 result := make(batchStream, len(tc.input1)+len(tc.input2))
53 result = mergeStreams(tc.input1, tc.input2, result, promchunk.BatchSize)
54 require.Equal(t, tc.output, result)
55 })
56 }
57 })
58}
59
60func mkBatch(from int64, enc encoding.Encoding) promchunk.Batch {
61 var result promchunk.Batch

Callers

nothing calls this directly

Calls 5

forEncodingsFunction · 0.85
mkBatchFunction · 0.85
mergeStreamsFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected