| 295 | } |
| 296 | |
| 297 | func TestIteratorContextCancelled(t *testing.T) { |
| 298 | t.Run("already cancelled", func(t *testing.T) { |
| 299 | testWalBlock(t, func(w *walBlock, _ []common.ID, _ []*tempopb.Trace) { |
| 300 | ctx, cancel := context.WithCancel(context.Background()) |
| 301 | cancel() |
| 302 | |
| 303 | _, err := w.Iterator(ctx) |
| 304 | require.Error(t, err) |
| 305 | require.ErrorIs(t, err, context.Canceled) |
| 306 | }) |
| 307 | }) |
| 308 | |
| 309 | t.Run("cancelled after creation", func(t *testing.T) { |
| 310 | testWalBlock(t, func(w *walBlock, _ []common.ID, _ []*tempopb.Trace) { |
| 311 | ctx, cancel := context.WithCancel(context.Background()) |
| 312 | |
| 313 | iter, err := w.Iterator(ctx) |
| 314 | require.NoError(t, err) |
| 315 | defer iter.Close() |
| 316 | |
| 317 | // Cancel the context after iterator creation. Subsequent Next calls |
| 318 | // go through walReaderAt.ReadAt which checks ctx.Err(). |
| 319 | cancel() |
| 320 | |
| 321 | _, _, err = iter.Next(ctx) |
| 322 | require.Error(t, err) |
| 323 | require.ErrorIs(t, err, context.Canceled) |
| 324 | }) |
| 325 | }) |
| 326 | } |
| 327 | |
| 328 | func TestWalBlockRaceConditionCheck(t *testing.T) { |
| 329 | meta := backend.NewBlockMeta("fake", uuid.New(), VersionString) |