@@ -42,3 +42,55 @@ def test_retry_backoff_factor_validation():
4242 configuration .retry_backoff_factor = 1
4343
4444 configuration .retry_backoff_factor = 3
45+
46+
47+ @mock .patch ("time.sleep" , return_value = None )
48+ def test_custom_retry_policy (sleep_mock ):
49+ """Test that a custom retry policy is used when provided"""
50+ import urllib3
51+
52+ # Create a custom retry policy with different settings
53+ custom_retry = urllib3 .util .Retry (
54+ total = 5 , # Different from default 3
55+ backoff_factor = 1 , # Different from default 2
56+ status_forcelist = [500 , 502 , 503 , 504 ],
57+ allowed_methods = ["GET" , "POST" ],
58+ )
59+
60+ configuration = Configuration (retry_policy = custom_retry )
61+
62+ with vcr .use_cassette ("tests/cassettes/test_retry/test_retry_errors.yaml" , record_mode = vcr .mode .NONE ):
63+ with ApiClient (configuration ) as api_client :
64+ api_instance = logs_api .LogsApi (api_client )
65+ logs = api_instance .list_logs_get ()
66+ assert len (logs .data ) == 10
67+ # With backoff_factor=1, sleep times are: 2, 4
68+ assert sleep_mock .call_count == 2
69+ assert sleep_mock .call_args_list [0 ][0 ][0 ] == 2
70+ assert sleep_mock .call_args_list [1 ][0 ][0 ] == 4
71+
72+
73+ def test_custom_retry_policy_overrides_enable_retry ():
74+ """Test that retry_policy takes precedence over enable_retry"""
75+ import urllib3
76+
77+ custom_retry = urllib3 .util .Retry (total = 10 )
78+ configuration = Configuration (
79+ enable_retry = True , # This should be ignored
80+ max_retries = 3 , # This should be ignored
81+ retry_policy = custom_retry ,
82+ )
83+
84+ # Verify the configuration accepts the custom policy
85+ assert configuration .retry_policy is custom_retry
86+ assert configuration .retry_policy .total == 10
87+
88+
89+ def test_default_retry_when_no_custom_policy ():
90+ """Test that default retry behavior works when no custom policy is provided"""
91+ configuration = Configuration (enable_retry = True , max_retries = 5 )
92+
93+ # Verify no custom policy is set
94+ assert configuration .retry_policy is None
95+ assert configuration .enable_retry is True
96+ assert configuration .max_retries == 5
0 commit comments