(t *testing.T)
| 15 | } |
| 16 | |
| 17 | func TestConcurrentGroup(t *testing.T) { |
| 18 | t.Parallel() |
| 19 | |
| 20 | t.Run("no goroutines", func(t *testing.T) { |
| 21 | t.Parallel() |
| 22 | |
| 23 | cg := utils.NewConcurrentGroup() |
| 24 | require.NoError(t, cg.Wait()) |
| 25 | }) |
| 26 | |
| 27 | t.Run("multiple goroutines, all ok", func(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | cg := utils.NewConcurrentGroup() |
| 31 | cg.Go(func() error { |
| 32 | return nil |
| 33 | }) |
| 34 | cg.Go(func() error { |
| 35 | return nil |
| 36 | }) |
| 37 | require.NoError(t, cg.Wait()) |
| 38 | }) |
| 39 | |
| 40 | t.Run("multiple goroutines, one err", func(t *testing.T) { |
| 41 | t.Parallel() |
| 42 | |
| 43 | cg := utils.NewConcurrentGroup() |
| 44 | oops := xerrors.New("oops") |
| 45 | cg.Go(func() error { |
| 46 | return oops |
| 47 | }) |
| 48 | cg.Go(func() error { |
| 49 | return nil |
| 50 | }) |
| 51 | require.ErrorIs(t, cg.Wait(), oops) |
| 52 | }) |
| 53 | |
| 54 | t.Run("multiple goroutines, multiple errs", func(t *testing.T) { |
| 55 | t.Parallel() |
| 56 | |
| 57 | cg := utils.NewConcurrentGroup() |
| 58 | oops := xerrors.New("oops") |
| 59 | eek := xerrors.New("eek") |
| 60 | cg.Go(func() error { |
| 61 | return oops |
| 62 | }) |
| 63 | cg.Go(func() error { |
| 64 | return eek |
| 65 | }) |
| 66 | |
| 67 | errs := cg.Wait() |
| 68 | require.ErrorIs(t, errs, oops) |
| 69 | require.ErrorIs(t, errs, eek) |
| 70 | }) |
| 71 | } |
| 72 | |
| 73 | func BenchmarkConcurrentGroup(b *testing.B) { |
| 74 | for i := 0; i < b.N; i++ { |
nothing calls this directly
no test coverage detected