@@ -27,6 +27,7 @@ type Benchmark struct {
27
27
loadSteps []BenchmarkStepFunc
28
28
validationSteps []BenchmarkStepFunc
29
29
30
+ panicRecover bool
30
31
prepareTimeout time.Duration
31
32
loadTimeout time.Duration
32
33
ignoreCodes []failure.Code
@@ -39,6 +40,7 @@ func NewBenchmark(opts ...BenchmarkOption) (*Benchmark, error) {
39
40
prepareSteps : []BenchmarkStepFunc {},
40
41
loadSteps : []BenchmarkStepFunc {},
41
42
validationSteps : []BenchmarkStepFunc {},
43
+ panicRecover : true ,
42
44
prepareTimeout : time .Duration (0 ),
43
45
loadTimeout : time .Duration (0 ),
44
46
ignoreCodes : []failure.Code {},
@@ -93,7 +95,7 @@ func (b *Benchmark) Start(parent context.Context) *BenchmarkResult {
93
95
}
94
96
defer prepareCancel ()
95
97
96
- if err := panicWrapper (func () error { return prepare (prepareCtx , step ) }); err != nil {
98
+ if err := panicWrapper (b . panicRecover , func () error { return prepare (prepareCtx , step ) }); err != nil {
97
99
for _ , ignore := range b .ignoreCodes {
98
100
if failure .IsCode (err , ignore ) {
99
101
goto Result
@@ -121,7 +123,7 @@ func (b *Benchmark) Start(parent context.Context) *BenchmarkResult {
121
123
for _ , load := range b .loadSteps {
122
124
func (f BenchmarkStepFunc ) {
123
125
loadParallel .Do (func (c context.Context ) {
124
- if err := panicWrapper (func () error { return f (c , step ) }); err != nil {
126
+ if err := panicWrapper (b . panicRecover , func () error { return f (c , step ) }); err != nil {
125
127
for _ , ignore := range b .ignoreCodes {
126
128
if failure .IsCode (err , ignore ) {
127
129
return
@@ -143,7 +145,7 @@ func (b *Benchmark) Start(parent context.Context) *BenchmarkResult {
143
145
144
146
step .setErrorCode (ErrValidation )
145
147
for _ , validation := range b .validationSteps {
146
- if err := panicWrapper (func () error { return validation (ctx , step ) }); err != nil {
148
+ if err := panicWrapper (b . panicRecover , func () error { return validation (ctx , step ) }); err != nil {
147
149
for _ , ignore := range b .ignoreCodes {
148
150
if failure .IsCode (err , ignore ) {
149
151
goto Result
@@ -197,7 +199,11 @@ func (b *Benchmark) IgnoreErrorCode(code failure.Code) {
197
199
b .ignoreCodes = append (b .ignoreCodes , code )
198
200
}
199
201
200
- func panicWrapper (f func () error ) (err error ) {
202
+ func panicWrapper (on bool , f func () error ) (err error ) {
203
+ if ! on {
204
+ return f ()
205
+ }
206
+
201
207
defer func () {
202
208
re := recover ()
203
209
if re == nil {
0 commit comments