MCPcopy Index your code
hub / github.com/coder/coder / TestConcurrentGroup

Function TestConcurrentGroup

aibridge/utils/concurrent_group_test.go:17–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15}
16
17func 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
73func BenchmarkConcurrentGroup(b *testing.B) {
74 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 5

WaitMethod · 0.95
GoMethod · 0.95
NewConcurrentGroupFunction · 0.92
RunMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected