(t *testing.T)
| 2328 | } |
| 2329 | |
| 2330 | func TestDeletedIterator(t *testing.T) { |
| 2331 | chk := chunkenc.NewXORChunk() |
| 2332 | app, err := chk.Appender() |
| 2333 | require.NoError(t, err) |
| 2334 | // Insert random stuff from (0, 1000). |
| 2335 | act := make([]sample, 1000) |
| 2336 | for i := range 1000 { |
| 2337 | act[i].t = int64(i) |
| 2338 | act[i].f = rand.Float64() |
| 2339 | app.Append(0, act[i].t, act[i].f) |
| 2340 | } |
| 2341 | |
| 2342 | cases := []struct { |
| 2343 | r tombstones.Intervals |
| 2344 | }{ |
| 2345 | {r: tombstones.Intervals{{Mint: 1, Maxt: 20}}}, |
| 2346 | {r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 20}, {Mint: 21, Maxt: 23}, {Mint: 25, Maxt: 30}}}, |
| 2347 | {r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 20}, {Mint: 20, Maxt: 30}}}, |
| 2348 | {r: tombstones.Intervals{{Mint: 1, Maxt: 10}, {Mint: 12, Maxt: 23}, {Mint: 25, Maxt: 30}}}, |
| 2349 | {r: tombstones.Intervals{{Mint: 1, Maxt: 23}, {Mint: 12, Maxt: 20}, {Mint: 25, Maxt: 30}}}, |
| 2350 | {r: tombstones.Intervals{{Mint: 1, Maxt: 23}, {Mint: 12, Maxt: 20}, {Mint: 25, Maxt: 3000}}}, |
| 2351 | {r: tombstones.Intervals{{Mint: 0, Maxt: 2000}}}, |
| 2352 | {r: tombstones.Intervals{{Mint: 500, Maxt: 2000}}}, |
| 2353 | {r: tombstones.Intervals{{Mint: 0, Maxt: 200}}}, |
| 2354 | {r: tombstones.Intervals{{Mint: 1000, Maxt: 20000}}}, |
| 2355 | } |
| 2356 | |
| 2357 | for _, c := range cases { |
| 2358 | i := int64(-1) |
| 2359 | it := &DeletedIterator{Iter: chk.Iterator(nil), Intervals: c.r[:]} |
| 2360 | ranges := c.r[:] |
| 2361 | for it.Next() == chunkenc.ValFloat { |
| 2362 | i++ |
| 2363 | for _, tr := range ranges { |
| 2364 | if tr.InBounds(i) { |
| 2365 | i = tr.Maxt + 1 |
| 2366 | ranges = ranges[1:] |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | require.Less(t, i, int64(1000)) |
| 2371 | |
| 2372 | ts, v := it.At() |
| 2373 | require.Equal(t, act[i].t, ts) |
| 2374 | require.Equal(t, act[i].f, v) |
| 2375 | } |
| 2376 | // There has been an extra call to Next(). |
| 2377 | i++ |
| 2378 | for _, tr := range ranges { |
| 2379 | if tr.InBounds(i) { |
| 2380 | i = tr.Maxt + 1 |
| 2381 | ranges = ranges[1:] |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | require.GreaterOrEqual(t, i, int64(1000)) |
| 2386 | require.NoError(t, it.Err()) |
| 2387 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…