MCPcopy Index your code
hub / github.com/riverqueue/river / TestDefaultClientRetryPolicy_NextRetry

Function TestDefaultClientRetryPolicy_NextRetry

retry_policy_test.go:19–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17var _ ClientRetryPolicy = &DefaultClientRetryPolicy{}
18
19func TestDefaultClientRetryPolicy_NextRetry(t *testing.T) {
20 t.Parallel()
21
22 type testBundle struct {
23 now time.Time
24 }
25
26 setup := func(t *testing.T) (*DefaultClientRetryPolicy, *testBundle) {
27 t.Helper()
28
29 var (
30 now = time.Now().UTC()
31 timeNowFunc = func() time.Time { return now }
32 )
33
34 return &DefaultClientRetryPolicy{timeNowFunc: timeNowFunc}, &testBundle{
35 now: now,
36 }
37 }
38
39 t.Run("Schedule", func(t *testing.T) {
40 t.Parallel()
41
42 retryPolicy, bundle := setup(t)
43
44 for attempt := 1; attempt < 10; attempt++ {
45 retrySecondsWithoutJitter := retryPolicy.retrySecondsWithoutJitter(attempt)
46 allowedDelta := timeutil.SecondsAsDuration(retrySecondsWithoutJitter * 0.2)
47
48 nextRetryAt := retryPolicy.NextRetry(&rivertype.JobRow{
49 Attempt: attempt,
50 AttemptedAt: &bundle.now,
51 Errors: make([]rivertype.AttemptError, attempt-1),
52 })
53 require.WithinDuration(t, bundle.now.Add(timeutil.SecondsAsDuration(retrySecondsWithoutJitter)), nextRetryAt, allowedDelta)
54 }
55 })
56
57 t.Run("MaxRetryDuration", func(t *testing.T) {
58 t.Parallel()
59
60 retryPolicy, bundle := setup(t)
61
62 maxRetryDuration := timeutil.SecondsAsDuration(maxDurationSeconds)
63
64 // First time the maximum will be hit.
65 require.Equal(t,
66 bundle.now.Add(maxRetryDuration),
67 retryPolicy.NextRetry(&rivertype.JobRow{
68 Attempt: 310,
69 AttemptedAt: &bundle.now,
70 Errors: make([]rivertype.AttemptError, 310-1),
71 }),
72 )
73
74 // And will be hit on all subsequent attempts as well.
75 require.Equal(t,
76 bundle.now.Add(maxRetryDuration),

Callers

nothing calls this directly

Calls 7

SecondsAsDurationFunction · 0.92
HelperMethod · 0.65
NowMethod · 0.65
RunMethod · 0.65
NextRetryMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…