File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,34 @@ import (
9
9
"github.com/fortytw2/leaktest"
10
10
)
11
11
12
+ // GuardConfig stores options for Guard function.
13
+ type GuardConfig struct {
14
+ timeout time.Duration
15
+ }
16
+
17
+ // GuardOption is an option for Guard function.
18
+ type GuardOption func (* GuardConfig )
19
+
20
+ // WithGuardTimeout sets timeout for the guard. Default is 5s.
21
+ func WithGuardTimeout (timeout time.Duration ) GuardOption {
22
+ return func (c * GuardConfig ) {
23
+ c .timeout = timeout
24
+ }
25
+ }
26
+
12
27
// Guard implements a test level timeout.
13
- func Guard (t * testing.T ) func () {
28
+ func Guard (t * testing.T , opts ... GuardOption ) func () {
29
+ cfg := GuardConfig {
30
+ timeout : 5 * time .Second ,
31
+ }
32
+ for _ , opt := range opts {
33
+ opt (& cfg )
34
+ }
35
+
14
36
done := make (chan struct {})
15
37
go func () {
16
38
select {
17
- case <- time .After (5 * time . Second ):
39
+ case <- time .After (cfg . timeout ):
18
40
err := pprof .Lookup ("goroutine" ).WriteTo (os .Stdout , 1 )
19
41
if err != nil {
20
42
panic (err )
You can’t perform that action at this time.
0 commit comments