Atlas › Test
TestConditionalRetryPolicy
Exact test identity: go.temporal.io/server/common/backoff/TestRetryPolicySuite/TestConditionalRetryPolicy
- Package
go.temporal.io/server/common/backoff
- Suite / test hierarchy
TestRetryPolicySuite/TestConditionalRetryPolicy
- Test
TestConditionalRetryPolicy
- Introduced at
- TestConditionalRetryPolicy Frontier kind: Test frontier
- Covered ranges
- 13
- Covered lines
- 50
- Covered files
- 1
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/common/backoff/retrypolicy.go 50 covered LOC · 13 ranges
Open complete file
80
81
// NewExponentialRetryPolicy returns an instance of ExponentialRetryPolicy using the provided initialInterval
82
>
func NewExponentialRetryPolicy(initialInterval time.Duration) *ExponentialRetryPolicy {
retrypolicy.go
83
>
p := &ExponentialRetryPolicy{
84
>
initialInterval: initialInterval,
85
>
backoffCoefficient: defaultBackoffCoefficient,
86
>
maximumInterval: defaultMaximumInterval,
87
>
expirationInterval: defaultExpirationInterval,
88
>
maximumAttempts: defaultMaximumAttempts,
89
>
}
90
>
91
>
return p
92
>
}
93
94
// NewRetrier is used for creating a new instance of Retrier
121
// This does *not* cause the policy to stop retrying when the interval between retries reaches the supplied duration.
122
// That is what WithExpirationInterval does. Instead, this prevents the interval from exceeding maximumInterval.
123
>
func (p *ExponentialRetryPolicy) WithMaximumInterval(maximumInterval time.Duration) *ExponentialRetryPolicy {
retrypolicy.go
124
>
p.maximumInterval = maximumInterval
125
>
return p
126
>
}
127
128
// WithExpirationInterval sets the absolute expiration interval for all retries
129
>
func (p *ExponentialRetryPolicy) WithExpirationInterval(expirationInterval time.Duration) *ExponentialRetryPolicy {
retrypolicy.go
130
>
p.expirationInterval = expirationInterval
131
>
return p
132
>
}
133
134
// WithMaximumAttempts sets the maximum number of retry attempts
203
// NewConditionalRetryPolicy returns a policy that delegates to whenTrue when
204
// predicate(err) is true, and whenFalse otherwise.
205
>
func NewConditionalRetryPolicy(predicate func(err error) bool, whenTrue, whenFalse RetryPolicy) *ConditionalRetryPolicy {
retrypolicy.go
206
>
return &ConditionalRetryPolicy{
207
>
predicate: predicate,
208
>
whenTrue: whenTrue,
209
>
whenFalse: whenFalse,
210
>
}
211
>
}
212
213
>
func (p *ConditionalRetryPolicy) ComputeNextDelay(elapsedTime time.Duration, numAttempts int, err error) time.Duration {
retrypolicy.go
214
>
if p.predicate(err) {
215
>
return p.whenTrue.ComputeNextDelay(elapsedTime, numAttempts, err)
retrypolicy.go
216
>
}
217
>
return p.whenFalse.ComputeNextDelay(elapsedTime, numAttempts, err)
retrypolicy.go
218
}
219
267
var _ RetryPolicy = (*ConstantDelayRetryPolicy)(nil)
268
269
>
func NewConstantDelayRetryPolicy(delay time.Duration) *ConstantDelayRetryPolicy {
retrypolicy.go
270
>
return &ConstantDelayRetryPolicy{
271
>
maximumAttempts: defaultMaximumAttempts,
272
>
jitterPct: defaultJitterPct,
273
>
delay: delay,
274
>
}
275
>
}
276
277
>
func (p *ConstantDelayRetryPolicy) WithMaximumAttempts(maximumAttempts int) *ConstantDelayRetryPolicy {
retrypolicy.go
278
>
p.maximumAttempts = maximumAttempts
279
>
return p
280
>
}
281
282
func (p *ConstantDelayRetryPolicy) WithJitter(jitterPct float64) *ConstantDelayRetryPolicy {
285
}
286
287
>
func (p *ConstantDelayRetryPolicy) ComputeNextDelay(_ time.Duration, attempt int, _ error) time.Duration {
retrypolicy.go
288
>
if p.maximumAttempts != noMaximumAttempts && attempt >= p.maximumAttempts {
290
>
}
291
293
}
294
295
>
func addJitter(duration time.Duration, jitterPct float64) time.Duration {
retrypolicy.go
296
>
return duration * time.Duration(1+jitterPct*rand.Float64())
297
>
}
298
299
func getJitterRand() *rand.Rand {