@@ -88,6 +88,40 @@ def mock_post(request):
88
88
assert bool (pattern .search (caplog .text ))
89
89
90
90
91
+ @pytest .mark .parametrize (
92
+ ("status_code" , "expect_retry" ),
93
+ [
94
+ [500 , False ],
95
+ [502 , True ],
96
+ [503 , True ],
97
+ [504 , True ],
98
+ ]
99
+ )
100
+ def test_unit_number_of_retries_in_5xx (status_code : int , expect_retry : bool ):
101
+ filename = "README.md"
102
+ backoff_strategy = BackoffStrategy (
103
+ initial_interval = 1 , max_interval = 10 , exponent = 1.5 , max_elapsed_time = 300
104
+ )
105
+ retries = RetryConfig (
106
+ strategy = "backoff" , backoff = backoff_strategy , retry_connection_errors = True
107
+ )
108
+
109
+ with requests_mock .Mocker () as mock :
110
+ mock .post ("https://api.unstructuredapp.io/general/v0/general" , status_code = status_code )
111
+ session = UnstructuredClient (api_key_auth = FAKE_KEY )
112
+
113
+ with open (filename , "rb" ) as f :
114
+ files = shared .Files (content = f .read (), file_name = filename )
115
+
116
+ req = shared .PartitionParameters (files = files )
117
+ with pytest .raises (Exception , match = f"unknown content-type received: None: Status { status_code } " ):
118
+ session .general .partition (req , retries = retries )
119
+ if expect_retry :
120
+ assert len (mock .request_history ) > 1
121
+ else :
122
+ assert len (mock .request_history ) == 1
123
+
124
+
91
125
def test_unit_backoff_strategy_logs_retries_connection_error (caplog ):
92
126
caplog .set_level (logging .INFO )
93
127
filename = "README.md"
0 commit comments