(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestForEach(t *testing.T) { |
| 76 | var ( |
| 77 | ctx = context.Background() |
| 78 | |
| 79 | // Keep track of processed jobs. |
| 80 | processedMx sync.Mutex |
| 81 | processed []string |
| 82 | ) |
| 83 | |
| 84 | jobs := []string{"a", "b", "c"} |
| 85 | |
| 86 | err := ForEach(ctx, CreateJobsFromStrings(jobs), 2, func(ctx context.Context, job any) error { |
| 87 | processedMx.Lock() |
| 88 | defer processedMx.Unlock() |
| 89 | processed = append(processed, job.(string)) |
| 90 | return nil |
| 91 | }) |
| 92 | |
| 93 | require.NoError(t, err) |
| 94 | assert.ElementsMatch(t, jobs, processed) |
| 95 | } |
| 96 | |
| 97 | func TestForEach_ShouldBreakOnFirstError_ContextCancellationHandled(t *testing.T) { |
| 98 | var ( |
nothing calls this directly
no test coverage detected