File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments