Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions task/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type Group struct {
}

// NewGroup creates new task group instance.
func NewGroup(ctx context.Context) *Group {
ctx, cancel := context.WithCancel(ctx)
func NewGroup() *Group {
ctx, cancel := context.WithCancel(context.Background())

return &Group{
ctx: ctx,
Expand Down
29 changes: 9 additions & 20 deletions task/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func TestGroup_Go(t *testing.T) {
t.Run("it runs the tasks", func(t *testing.T) {
t.Parallel()

ctx := context.Background()

group := task.NewGroup(ctx)
group := task.NewGroup()
foo := NewTestTask(nil)
bar := NewTestTask(nil)

Expand All @@ -67,7 +65,7 @@ func TestGroup_Go(t *testing.T) {
foo.RunUntil <- nil
bar.RunUntil <- nil

err := group.Wait(ctx)
err := group.Wait(context.Background())
assert.NoError(t, err)

assert.Equal(t, 1, foo.RunCount)
Expand All @@ -79,9 +77,7 @@ func TestGroup_Go(t *testing.T) {
t.Run("when a task from the group returns an error, it cancels all the tasks", func(t *testing.T) {
t.Parallel()

ctx := context.Background()

group := task.NewGroup(ctx)
group := task.NewGroup()
foo := NewTestTask(assert.AnError)
bar := NewTestTask(nil)

Expand All @@ -94,7 +90,7 @@ func TestGroup_Go(t *testing.T) {
foo.RunUntil <- assert.AnError
}()

err := group.Wait(ctx)
err := group.Wait(context.Background())
assert.EqualError(t, err, assert.AnError.Error())

assert.Equal(t, 1, foo.RunCount)
Expand All @@ -106,9 +102,7 @@ func TestGroup_Go(t *testing.T) {
t.Run("when wait deadline is exceeded, it cancels all tasks", func(t *testing.T) {
t.Parallel()

ctx := context.Background()

group := task.NewGroup(ctx)
group := task.NewGroup()

foo := NewTestTask(assert.AnError)
bar := NewTestTask(nil)
Expand All @@ -132,8 +126,7 @@ func TestGroup_Go(t *testing.T) {
t.Run("when the group is canceled, it does not start new tasks", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
group := task.NewGroup(ctx)
group := task.NewGroup()
foo := NewTestTask(nil)
bar := NewTestTask(nil)

Expand All @@ -154,9 +147,7 @@ func TestGroup_Cancel(t *testing.T) {
t.Run("it cancels all the tasks", func(t *testing.T) {
t.Parallel()

ctx := context.Background()

group := task.NewGroup(ctx)
group := task.NewGroup()
foo := NewTestTask(nil)
bar := NewTestTask(nil)

Expand All @@ -180,9 +171,7 @@ func TestGroup_Cancel(t *testing.T) {
}

func BenchmarkGroup_Go(b *testing.B) {
ctx := context.Background()

group := task.NewGroup(ctx)
group := task.NewGroup()

b.ResetTimer()
b.ReportAllocs()
Expand All @@ -191,5 +180,5 @@ func BenchmarkGroup_Go(b *testing.B) {
group.Go(func(ctx context.Context) error { return nil })
}

group.Wait(ctx)
group.Wait(context.TODO())
}
Loading