Skip to content

Commit

Permalink
Prevent NPE in GroupContext
Browse files Browse the repository at this point in the history
  • Loading branch information
alitto committed May 9, 2022
1 parent 44f8f0d commit 47ab16c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions group_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,18 @@ func TestGroupContextWithError(t *testing.T) {
assertEqual(t, int32(5), atomic.LoadInt32(&startedCount))
assertEqual(t, int32(4), atomic.LoadInt32(&doneCount))
}

func TestGroupContextWithNilContext(t *testing.T) {

pool := pond.New(3, 100)

var thrownPanic interface{}
func() {
defer func() {
thrownPanic = recover()
}()
pool.GroupContext(nil)
}()

assertEqual(t, "a non-nil context needs to be specified when using GroupContext", thrownPanic)
}
5 changes: 5 additions & 0 deletions pond.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ func (p *WorkerPool) Group() *TaskGroup {
// The derived Context is canceled the first time a function submitted to the group
// returns a non-nil error or the first time Wait returns, whichever occurs first.
func (p *WorkerPool) GroupContext(ctx context.Context) (*TaskGroupWithContext, context.Context) {

if ctx == nil {
panic("a non-nil context needs to be specified when using GroupContext")
}

ctx, cancel := context.WithCancel(ctx)
return &TaskGroupWithContext{
TaskGroup: TaskGroup{
Expand Down

0 comments on commit 47ab16c

Please sign in to comment.