6
6
import configargparse
7
7
8
8
from dsdk import BaseBatchJob , Block
9
+ from dsdk .utils import retry
9
10
10
11
11
12
def test_batch (monkeypatch ):
@@ -23,3 +24,67 @@ def run(self):
23
24
batch .run ()
24
25
assert len (batch .evidence ) == 1
25
26
assert batch .evidence ["test" ] == 42
27
+
28
+
29
+ def test_retry_other_exception ():
30
+ """Test retry other exception."""
31
+
32
+ exceptions_in = [
33
+ RuntimeError ("what?" ),
34
+ NotImplementedError ("how?" ),
35
+ RuntimeError ("no!" ),
36
+ ]
37
+ actual = []
38
+ expected = [1.0 , 1.5 , 2.25 ]
39
+
40
+ def sleep (wait : float ):
41
+ actual .append (wait )
42
+
43
+ @retry (
44
+ (NotImplementedError , RuntimeError ),
45
+ retries = 4 ,
46
+ delay = 1.0 ,
47
+ backoff = 1.5 ,
48
+ sleep = sleep ,
49
+ )
50
+ def explode ():
51
+ raise exceptions_in .pop ()
52
+
53
+ try :
54
+ explode ()
55
+ raise AssertionError ("IndexError expected" )
56
+ except IndexError :
57
+ assert actual == expected
58
+
59
+
60
+ def test_retry_exhausted ():
61
+ """Test retry."""
62
+
63
+ exceptions_in = [
64
+ RuntimeError ("what?" ),
65
+ NotImplementedError ("how?" ),
66
+ RuntimeError ("no!" ),
67
+ NotImplementedError ("when?" ),
68
+ ]
69
+ actual = []
70
+ expected = [1.0 , 1.5 ]
71
+
72
+ def sleep (wait : float ):
73
+ actual .append (wait )
74
+
75
+ @retry (
76
+ (NotImplementedError , RuntimeError ),
77
+ retries = 2 ,
78
+ delay = 1.0 ,
79
+ backoff = 1.5 ,
80
+ sleep = sleep ,
81
+ )
82
+ def explode ():
83
+ raise exceptions_in .pop ()
84
+
85
+ try :
86
+ explode ()
87
+ raise AssertionError ("NotImplementedError expected" )
88
+ except NotImplementedError as exception :
89
+ assert actual == expected
90
+ assert str (exception ) == "when?"
0 commit comments