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