(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func TestContextPool(t *testing.T) { |
| 38 | t.Parallel() |
| 39 | |
| 40 | err1 := errors.New("err1") |
| 41 | err2 := errors.New("err2") |
| 42 | bgctx := context.Background() |
| 43 | |
| 44 | t.Run("panics on configuration after init", func(t *testing.T) { |
| 45 | t.Run("before wait", func(t *testing.T) { |
| 46 | t.Parallel() |
| 47 | g := New().WithContext(context.Background()) |
| 48 | g.Go(func(context.Context) error { return nil }) |
| 49 | require.Panics(t, func() { g.WithMaxGoroutines(10) }) |
| 50 | }) |
| 51 | |
| 52 | t.Run("after wait", func(t *testing.T) { |
| 53 | t.Parallel() |
| 54 | g := New().WithContext(context.Background()) |
| 55 | g.Go(func(context.Context) error { return nil }) |
| 56 | _ = g.Wait() |
| 57 | require.Panics(t, func() { g.WithMaxGoroutines(10) }) |
| 58 | }) |
| 59 | }) |
| 60 | |
| 61 | t.Run("behaves the same as ErrorGroup", func(t *testing.T) { |
| 62 | t.Parallel() |
| 63 | |
| 64 | t.Run("wait returns no error if no errors", func(t *testing.T) { |
| 65 | t.Parallel() |
| 66 | p := New().WithContext(bgctx) |
| 67 | p.Go(func(context.Context) error { return nil }) |
| 68 | require.NoError(t, p.Wait()) |
| 69 | }) |
| 70 | |
| 71 | t.Run("wait errors if func returns error", func(t *testing.T) { |
| 72 | t.Parallel() |
| 73 | p := New().WithContext(bgctx) |
| 74 | p.Go(func(context.Context) error { return err1 }) |
| 75 | require.ErrorIs(t, p.Wait(), err1) |
| 76 | }) |
| 77 | |
| 78 | t.Run("wait error is all returned errors", func(t *testing.T) { |
| 79 | t.Parallel() |
| 80 | p := New().WithErrors().WithContext(bgctx) |
| 81 | p.Go(func(context.Context) error { return err1 }) |
| 82 | p.Go(func(context.Context) error { return nil }) |
| 83 | p.Go(func(context.Context) error { return err2 }) |
| 84 | err := p.Wait() |
| 85 | require.ErrorIs(t, err, err1) |
| 86 | require.ErrorIs(t, err, err2) |
| 87 | }) |
| 88 | }) |
| 89 | |
| 90 | t.Run("context error propagates", func(t *testing.T) { |
| 91 | t.Parallel() |
| 92 | |
| 93 | t.Run("canceled", func(t *testing.T) { |
| 94 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…