MCPcopy Index your code
hub / github.com/sourcegraph/conc / TestErrorPool

Function TestErrorPool

pool/error_pool_test.go:31–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestErrorPool(t *testing.T) {
32 t.Parallel()
33
34 err1 := errors.New("err1")
35 err2 := errors.New("err2")
36
37 t.Run("panics on configuration after init", func(t *testing.T) {
38 t.Run("before wait", func(t *testing.T) {
39 t.Parallel()
40 g := New().WithErrors()
41 g.Go(func() error { return nil })
42 require.Panics(t, func() { g.WithMaxGoroutines(10) })
43 })
44
45 t.Run("after wait", func(t *testing.T) {
46 t.Parallel()
47 g := New().WithErrors()
48 g.Go(func() error { return nil })
49 _ = g.Wait()
50 require.Panics(t, func() { g.WithMaxGoroutines(10) })
51 })
52 })
53
54 t.Run("wait returns no error if no errors", func(t *testing.T) {
55 t.Parallel()
56 g := New().WithErrors()
57 g.Go(func() error { return nil })
58 require.NoError(t, g.Wait())
59 })
60
61 t.Run("wait error if func returns error", func(t *testing.T) {
62 t.Parallel()
63 g := New().WithErrors()
64 g.Go(func() error { return err1 })
65 require.ErrorIs(t, g.Wait(), err1)
66 })
67
68 t.Run("wait error is all returned errors", func(t *testing.T) {
69 t.Parallel()
70 g := New().WithErrors()
71 g.Go(func() error { return err1 })
72 g.Go(func() error { return nil })
73 g.Go(func() error { return err2 })
74 err := g.Wait()
75 require.ErrorIs(t, err, err1)
76 require.ErrorIs(t, err, err2)
77 })
78
79 t.Run("propagates panics", func(t *testing.T) {
80 t.Parallel()
81 g := New().WithErrors()
82 for i := 0; i < 10; i++ {
83 i := i
84 g.Go(func() error {
85 if i == 5 {
86 panic("fatal")
87 }
88 return nil

Callers

nothing calls this directly

Calls 5

NewFunction · 0.70
WithErrorsMethod · 0.45
GoMethod · 0.45
WithMaxGoroutinesMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…