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

Function TestWaitGroup

waitgroup_test.go:40–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestWaitGroup(t *testing.T) {
41 t.Parallel()
42
43 t.Run("ctor", func(t *testing.T) {
44 t.Parallel()
45 wg := NewWaitGroup()
46 require.IsType(t, &WaitGroup{}, wg)
47 })
48
49 t.Run("all spawned run", func(t *testing.T) {
50 t.Parallel()
51 var count atomic.Int64
52 var wg WaitGroup
53 for i := 0; i < 100; i++ {
54 wg.Go(func() {
55 count.Add(1)
56 })
57 }
58 wg.Wait()
59 require.Equal(t, count.Load(), int64(100))
60 })
61
62 t.Run("panic", func(t *testing.T) {
63 t.Parallel()
64
65 t.Run("is propagated", func(t *testing.T) {
66 t.Parallel()
67 var wg WaitGroup
68 wg.Go(func() {
69 panic("super bad thing")
70 })
71 require.Panics(t, wg.Wait)
72 })
73
74 t.Run("one is propagated", func(t *testing.T) {
75 t.Parallel()
76 var wg WaitGroup
77 wg.Go(func() {
78 panic("super bad thing")
79 })
80 wg.Go(func() {
81 panic("super badder thing")
82 })
83 require.Panics(t, wg.Wait)
84 })
85
86 t.Run("non-panics do not overwrite panic", func(t *testing.T) {
87 t.Parallel()
88 var wg WaitGroup
89 wg.Go(func() {
90 panic("super bad thing")
91 })
92 for i := 0; i < 10; i++ {
93 wg.Go(func() {})
94 }
95 require.Panics(t, wg.Wait)
96 })
97

Callers

nothing calls this directly

Calls 4

GoMethod · 0.95
WaitMethod · 0.95
WaitAndRecoverMethod · 0.95
NewWaitGroupFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…