TestChunkReader_ConcurrentReads checks that the chunk result can be read concurrently. Regression test for https://github.com/prometheus/prometheus/pull/6514.
(t *testing.T)
| 3235 | // TestChunkReader_ConcurrentReads checks that the chunk result can be read concurrently. |
| 3236 | // Regression test for https://github.com/prometheus/prometheus/pull/6514. |
| 3237 | func TestChunkReader_ConcurrentReads(t *testing.T) { |
| 3238 | t.Parallel() |
| 3239 | chks := []chunks.Meta{ |
| 3240 | assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 1, nil, nil}}), |
| 3241 | assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 2, nil, nil}}), |
| 3242 | assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 3, nil, nil}}), |
| 3243 | assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 4, nil, nil}}), |
| 3244 | assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 5, nil, nil}}), |
| 3245 | } |
| 3246 | |
| 3247 | tempDir := t.TempDir() |
| 3248 | |
| 3249 | chunkw, err := chunks.NewWriter(tempDir) |
| 3250 | require.NoError(t, err) |
| 3251 | |
| 3252 | require.NoError(t, chunkw.WriteChunks(chks...)) |
| 3253 | require.NoError(t, chunkw.Close()) |
| 3254 | |
| 3255 | r, err := chunks.NewDirReader(tempDir, nil) |
| 3256 | require.NoError(t, err) |
| 3257 | |
| 3258 | var wg sync.WaitGroup |
| 3259 | for _, chk := range chks { |
| 3260 | for range 100 { |
| 3261 | wg.Add(1) |
| 3262 | go func(chunk chunks.Meta) { |
| 3263 | defer wg.Done() |
| 3264 | |
| 3265 | chkAct, iterable, err := r.ChunkOrIterable(chunk) |
| 3266 | require.NoError(t, err) |
| 3267 | require.Nil(t, iterable) |
| 3268 | require.Equal(t, chunk.Chunk.Bytes(), chkAct.Bytes()) |
| 3269 | }(chk) |
| 3270 | } |
| 3271 | wg.Wait() |
| 3272 | } |
| 3273 | require.NoError(t, r.Close()) |
| 3274 | } |
| 3275 | |
| 3276 | // TestCompactHead ensures that the head compaction |
| 3277 | // creates a block that is ready for loading and |
nothing calls this directly
no test coverage detected
searching dependent graphs…