Skip to content

Commit e8fb035

Browse files
committed
pool: add WithCancelOnError and panic test case for ResultContextPool
1 parent f978b8f commit e8fb035

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pool/result_context_pool_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213

1314
"github.com/sourcegraph/sourcegraph/lib/errors"
@@ -100,6 +101,29 @@ func TestResultContextPool(t *testing.T) {
100101
require.ErrorIs(t, err, err1)
101102
})
102103

104+
t.Run("WithCancelOnError and panic", func(t *testing.T) {
105+
t.Parallel()
106+
p := NewWithResults[int]().
107+
WithContext(context.Background()).
108+
WithCancelOnError()
109+
var cancelledTasks atomic.Int64
110+
p.Go(func(ctx context.Context) (int, error) {
111+
<-ctx.Done()
112+
cancelledTasks.Add(1)
113+
return 0, ctx.Err()
114+
})
115+
p.Go(func(ctx context.Context) (int, error) {
116+
<-ctx.Done()
117+
cancelledTasks.Add(1)
118+
return 0, ctx.Err()
119+
})
120+
p.Go(func(ctx context.Context) (int, error) {
121+
panic("abort!")
122+
})
123+
assert.Panics(t, func() { _, _ = p.Wait() })
124+
assert.EqualValues(t, 2, cancelledTasks.Load())
125+
})
126+
103127
t.Run("no WithCancelOnError", func(t *testing.T) {
104128
t.Parallel()
105129
g := NewWithResults[int]().WithContext(context.Background())

0 commit comments

Comments
 (0)