Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Pastro committed Jan 11, 2023
1 parent c8dfb40 commit 83a01d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions waitgroup.go
Expand Up @@ -42,9 +42,9 @@ func (h *WaitGroup) Wait() {
h.pc.Repanic()
}

// WaitSafe will block until all goroutines spawned with Go exit and will
// return a *panics.RecoveredPanic if one of the child goroutines panics.
func (h *WaitGroup) WaitSafe() *panics.RecoveredPanic {
// WaitAndRecover will block until all goroutines spawned with Go exit and
// will return a *panics.RecoveredPanic if one of the child goroutines panics.
func (h *WaitGroup) WaitAndRecover() *panics.RecoveredPanic {
h.wg.Wait()

// Return a recovered panic if we caught one from a child goroutine.
Expand Down
22 changes: 11 additions & 11 deletions waitgroup_test.go
Expand Up @@ -99,30 +99,30 @@ func TestWaitGroup(t *testing.T) {
require.Equal(t, int64(2), i.Load())
})

t.Run("is caught by waitsafe", func(t *testing.T) {
t.Run("is caught by waitandrecover", func(t *testing.T) {
t.Parallel()
var wg WaitGroup
wg.Go(func() {
panic("super bad thing")
})
p := wg.WaitSafe()
require.Contains(t, p.Error(), "super bad thing", p.Error())
p := wg.WaitAndRecover()
require.Equal(t, p.Value, "super bad thing")
})

t.Run("one is caught by waitsafe", func(t *testing.T) {
t.Run("one is caught by waitandrecover", func(t *testing.T) {
t.Parallel()
var wg WaitGroup
wg.Go(func() {
panic("one bad thing")
panic("super bad thing")
})
wg.Go(func() {
panic("another bad thing")
panic("super badder thing")
})
p := wg.WaitSafe()
require.Contains(t, p.Error(), "bad thing", p.Error())
p := wg.WaitAndRecover()
require.NotNil(t, p)
})

t.Run("nonpanics run successfully with waitsafe", func(t *testing.T) {
t.Run("nonpanics run successfully with waitandrecover", func(t *testing.T) {
t.Parallel()
var wg WaitGroup
var i atomic.Int64
Expand All @@ -135,8 +135,8 @@ func TestWaitGroup(t *testing.T) {
wg.Go(func() {
i.Add(1)
})
p := wg.WaitSafe()
require.Contains(t, p.Error(), "super bad thing", p.Error())
p := wg.WaitAndRecover()
require.Equal(t, p.Value, "super bad thing")
require.Equal(t, int64(2), i.Load())
})
})
Expand Down

0 comments on commit 83a01d6

Please sign in to comment.