@@ -9,6 +9,81 @@ defmodule Lightning.RetryTest do
9
9
setup :set_mox_from_context
10
10
setup :verify_on_exit!
11
11
12
+ describe "with_retry/2 non-retryable raises" do
13
+ test "bubbles non-DB exceptions (reraise path)" do
14
+ assert_raise RuntimeError , "boom" , fn ->
15
+ Retry . with_retry ( fn -> raise "boom" end ,
16
+ initial_delay_ms: 0 ,
17
+ jitter: false
18
+ )
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "option parsing fallbacks (:error branches)" do
24
+ test "string parse failures fall back to safe defaults" do
25
+ attempts = :counters . new ( 1 , [ ] )
26
+
27
+ result =
28
+ Retry . with_retry (
29
+ fn ->
30
+ :counters . add ( attempts , 1 , 1 )
31
+ { :error , % DBConnection.ConnectionError { message: "x" } }
32
+ end ,
33
+ max_attempts: "not-a-number" ,
34
+ initial_delay_ms: "nope" ,
35
+ max_delay_ms: "nah" ,
36
+ backoff_factor: "??" ,
37
+ timeout_ms: "zzz" ,
38
+ jitter: true
39
+ )
40
+
41
+ assert { :error , % DBConnection.ConnectionError { } } = result
42
+ assert :counters . get ( attempts , 1 ) == 1
43
+ end
44
+
45
+ test "non-numeric atoms hit generic to_int/to_float fallbacks" do
46
+ attempts = :counters . new ( 1 , [ ] )
47
+
48
+ result =
49
+ Retry . with_retry (
50
+ fn ->
51
+ :counters . add ( attempts , 1 , 1 )
52
+ { :error , % DBConnection.ConnectionError { message: "y" } }
53
+ end ,
54
+ max_attempts: :foo ,
55
+ backoff_factor: :bar ,
56
+ timeout_ms: :baz ,
57
+ initial_delay_ms: :qux ,
58
+ jitter: false
59
+ )
60
+
61
+ assert { :error , % DBConnection.ConnectionError { } } = result
62
+ assert :counters . get ( attempts , 1 ) == 1
63
+ end
64
+ end
65
+
66
+ describe "calculate_next_delay/2 with jitter but zero base delay" do
67
+ test "falls back to base delay when base_delay == 0" do
68
+ attempts = :counters . new ( 1 , [ ] )
69
+
70
+ result =
71
+ Retry . with_retry (
72
+ fn ->
73
+ :counters . add ( attempts , 1 , 1 )
74
+ { :error , % DBConnection.ConnectionError { message: "z" } }
75
+ end ,
76
+ max_attempts: 2 ,
77
+ initial_delay_ms: 0 ,
78
+ jitter: true ,
79
+ timeout_ms: 50
80
+ )
81
+
82
+ assert { :error , % DBConnection.ConnectionError { } } = result
83
+ assert :counters . get ( attempts , 1 ) == 2
84
+ end
85
+ end
86
+
12
87
describe "retriable_error?/1" do
13
88
test "returns true for {:error, %DBConnection.ConnectionError{}}" do
14
89
assert Retry . retriable_error? ( { :error , % DBConnection.ConnectionError { } } )
0 commit comments