Skip to content

Commit 07c4794

Browse files
fuweidqiutongs
authored andcommitted
pkg/failpoint: add DelegatedEval API
Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit 1ae6e8b) Signed-off-by: Qiutong Song <[email protected]>
1 parent 4a5bc05 commit 07c4794

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

pkg/failpoint/fail.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
"time"
2626
)
2727

28+
// EvalFn is the func type about delegated evaluation.
29+
type EvalFn func() error
30+
2831
// Type is the type of failpoint to specifies which action to take.
2932
type Type int
3033

@@ -100,6 +103,12 @@ func NewFailpoint(fnName string, terms string) (*Failpoint, error) {
100103

101104
// Evaluate evaluates a failpoint.
102105
func (fp *Failpoint) Evaluate() error {
106+
fn := fp.DelegatedEval()
107+
return fn()
108+
}
109+
110+
// DelegatedEval evaluates a failpoint but delegates to caller to fire that.
111+
func (fp *Failpoint) DelegatedEval() EvalFn {
103112
var target *failpointEntry
104113

105114
func() {
@@ -118,9 +127,9 @@ func (fp *Failpoint) Evaluate() error {
118127
}()
119128

120129
if target == nil {
121-
return nil
130+
return nopEvalFn
122131
}
123-
return target.evaluate()
132+
return target.evaluate
124133
}
125134

126135
// Failpoint returns the current state of control in string format.
@@ -291,3 +300,7 @@ func parseInt64(term []byte, terminate byte, val *int64) ([]byte, error) {
291300
*val = v
292301
return term[i+1:], nil
293302
}
303+
304+
func nopEvalFn() error {
305+
return nil
306+
}

0 commit comments

Comments
 (0)