Skip to content

Commit

Permalink
wg test
Browse files Browse the repository at this point in the history
  • Loading branch information
daheige committed Jan 15, 2022
1 parent d2557f7 commit 89851fd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion waitgroup/waitgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,27 @@ func TestWrapper(t *testing.T) {
wg.Wrap(func() {
log.Println("1111")
})

for i := 0; i < 10*10000; i++ {
// The method of copying is used here to avoid the i
// in the wrap func being the same variable
index := i
wg.Wrap(func() {
log.Printf("current index: %d\n", index)
})
}

wg.WrapWithRecover(func() {
log.Println(2222)
panic("mock panic test")
})

wg.Wait()
}

/*
2022/01/15 17:58:32 current index: 99998
2022/01/15 17:58:32 current index: 99999
2022/01/15 17:58:32 exec recover:mock panic test
--- PASS: TestWrapper (4.66s)
PASS
*/

0 comments on commit 89851fd

Please sign in to comment.