Atlas › Test

3

Exact test identity: go.temporal.io/server/common/backoff/TestCron/3

Package
go.temporal.io/server/common/backoff
Suite / test hierarchy
TestCron/3
Test
3
Introduced at
2, 3, +10 Frontier kind: Test frontier
Covered ranges
15
Covered lines
46
Covered files
3

Co-introduced tests

11 other tests enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/backoff/cron.go 24 covered LOC · 11 ranges

Open complete file

13
14 // ValidateSchedule validates a cron schedule spec
15 > func ValidateSchedule(cronSchedule string) error { cron.go
16 > if cronSchedule == "" {
17 return nil
18 }
19 > schedule, err := cron.ParseStandard(cronSchedule) cron.go
20 > if err != nil {
21 return serviceerror.NewInvalidArgument("invalid CronSchedule.")
22 }
23 > nextTime := schedule.Next(time.Now().UTC()) cron.go
24 > if nextTime.IsZero() {
25 // no time can be found to satisfy the schedule
26 return serviceerror.NewInvalidArgument("invalid CronSchedule, no time can be found to satisfy the schedule")
27 }
28 > return nil cron.go
29 }
30
31 // GetBackoffForNextSchedule calculates the backoff time for the next run given
32 // a cronSchedule, current scheduled time, and now.
33 > func GetBackoffForNextSchedule(cronSchedule string, scheduledTime time.Time, now time.Time) time.Duration { cron.go
34 > if len(cronSchedule) == 0 {
35 return NoBackoff
36 }
37
38 > schedule, err := cron.ParseStandard(cronSchedule) cron.go
39 > if err != nil {
40 return NoBackoff
41 }
42
43 > scheduledUTCTime := scheduledTime.UTC() cron.go
44 > nowUTC := now.UTC()
45 >
46 > var nextScheduleTime time.Time
47 > if nowUTC.Before(scheduledUTCTime) {
48 nextScheduleTime = scheduledUTCTime
49 > } else { cron.go
50 > nextScheduleTime = schedule.Next(scheduledUTCTime) cron.go
51 > // Calculate the next schedule start time which is nearest to now (right after now).
52 > for !nextScheduleTime.IsZero() && nextScheduleTime.Before(nowUTC) {
53 nextScheduleTime = schedule.Next(nextScheduleTime)
54 }
55 }
56 > if nextScheduleTime.IsZero() { cron.go
57 // no time can be found to satisfy the schedule
58 return NoBackoff
59 }
60
61 > backoffInterval := nextScheduleTime.Sub(nowUTC) cron.go
62 > roundedInterval := time.Second * time.Duration(convert.Int64Ceil(backoffInterval.Seconds()))
63 > return roundedInterval
64 }
65
go.temporal.io/server/common/backoff/retrypolicy.go 19 covered LOC · 3 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
go.temporal.io/server/common/convert/convert.go 3 covered LOC · 1 range

Open complete file

12
13 // Int64Ceil return the int64 ceil of a float64
14 > func Int64Ceil(v float64) int64 { convert.go
15 > return int64(math.Ceil(v))
16 > }
17
18 func IntToString(v int) string {