21
21
package goleak
22
22
23
23
import (
24
- "errors"
25
24
"strings"
26
25
"time"
27
26
@@ -33,14 +32,10 @@ type Option interface {
33
32
apply (* opts )
34
33
}
35
34
36
- const (
37
- // We retry up to default 20 times if we can't find the goroutine that
38
- // we are looking for.
39
- _defaultRetryAttempts = 20
40
- // In between each retry attempt, sleep for up to default 100 microseconds
41
- // to let any running goroutine completes.
42
- _defaultSleepInterval = 100 * time .Microsecond
43
- )
35
+ // We retry up to 20 times if we can't find the goroutine that
36
+ // we are looking for. In between each attempt, we will sleep for
37
+ // a short while to let any running goroutines complete.
38
+ const _defaultRetries = 20
44
39
45
40
type opts struct {
46
41
filters []func (stack.Stack ) bool
@@ -58,17 +53,6 @@ func (o *opts) apply(opts *opts) {
58
53
opts .cleanup = o .cleanup
59
54
}
60
55
61
- // validate the options.
62
- func (o * opts ) validate () error {
63
- if o .maxRetries < 0 {
64
- return errors .New ("maxRetryAttempts should be greater than 0" )
65
- }
66
- if o .maxSleep <= 0 {
67
- return errors .New ("maxSleepInterval should be greater than 0s" )
68
- }
69
- return nil
70
- }
71
-
72
56
// optionFunc lets us easily write options without a custom type.
73
57
type optionFunc func (* opts )
74
58
@@ -123,25 +107,12 @@ func IgnoreCurrent() Option {
123
107
})
124
108
}
125
109
126
- // MaxSleepInterval sets the maximum sleep time in-between each retry attempt.
127
- // The sleep duration grows in an exponential backoff, to a maximum of the value specified here.
128
- // If not configured, default to 100 microseconds.
129
- func MaxSleepInterval (d time.Duration ) Option {
110
+ func maxSleep (d time.Duration ) Option {
130
111
return optionFunc (func (opts * opts ) {
131
112
opts .maxSleep = d
132
113
})
133
114
}
134
115
135
- // MaxRetryAttempts sets the retry upper limit.
136
- // When finding extra goroutines, we'll retry until all goroutines complete
137
- // or end up with the maximum retry attempts.
138
- // If not configured, default to 20 times.
139
- func MaxRetryAttempts (num int ) Option {
140
- return optionFunc (func (opts * opts ) {
141
- opts .maxRetries = num
142
- })
143
- }
144
-
145
116
func addFilter (f func (stack.Stack ) bool ) Option {
146
117
return optionFunc (func (opts * opts ) {
147
118
opts .filters = append (opts .filters , f )
@@ -150,8 +121,8 @@ func addFilter(f func(stack.Stack) bool) Option {
150
121
151
122
func buildOpts (options ... Option ) * opts {
152
123
opts := & opts {
153
- maxRetries : _defaultRetryAttempts ,
154
- maxSleep : _defaultSleepInterval ,
124
+ maxRetries : _defaultRetries ,
125
+ maxSleep : 100 * time . Millisecond ,
155
126
}
156
127
opts .filters = append (opts .filters ,
157
128
isTestStack ,
@@ -162,7 +133,6 @@ func buildOpts(options ...Option) *opts {
162
133
for _ , option := range options {
163
134
option .apply (opts )
164
135
}
165
-
166
136
return opts
167
137
}
168
138
0 commit comments