19
19
from botocore .config import Config
20
20
from botocore .exceptions import (
21
21
ClientError ,
22
+ ConnectionError ,
22
23
ParamValidationError ,
23
24
UnsupportedS3AccesspointConfigurationError ,
24
25
UnsupportedS3ConfigurationError ,
@@ -2191,6 +2192,32 @@ def test_checksum_content_encoding(content_encoding, expected_header):
2191
2192
assert request_headers ["Content-Encoding" ] == expected_header
2192
2193
2193
2194
2195
+ @mock .patch ('botocore.endpoint.URLLib3Session.send' )
2196
+ @mock .patch ('botocore.client.apply_request_checksum' )
2197
+ def test_retries_reuse_request_checksum (
2198
+ mock_apply_request_checksum , mock_urllib3_session_send
2199
+ ):
2200
+ # Force retry behavior.
2201
+ mock_urllib3_session_send .side_effect = ConnectionError (error = 'Fake error' )
2202
+ op_kwargs = {
2203
+ "Bucket" : "mybucket" ,
2204
+ "Key" : "mykey" ,
2205
+ "Body" : b"foo" ,
2206
+ "ChecksumAlgorithm" : "CRC32" ,
2207
+ }
2208
+ s3 = _create_s3_client (
2209
+ retries = {
2210
+ 'max_attempts' : 2 ,
2211
+ }
2212
+ )
2213
+ with pytest .raises (ConnectionError ):
2214
+ s3 .put_object (** op_kwargs )
2215
+ # Ensure sending request was retried.
2216
+ assert mock_urllib3_session_send .call_count == 2
2217
+ # But request checksum was only calculated once.
2218
+ assert mock_apply_request_checksum .call_count == 1
2219
+
2220
+
2194
2221
def _s3_addressing_test_cases ():
2195
2222
# The default behavior for DNS compatible buckets
2196
2223
yield dict (
@@ -3255,6 +3282,7 @@ def _create_s3_client(
3255
3282
s3_config = None ,
3256
3283
signature_version = 's3v4' ,
3257
3284
use_fips_endpoint = None ,
3285
+ retries = None ,
3258
3286
):
3259
3287
environ = {}
3260
3288
with mock .patch ('os.environ' , environ ):
@@ -3268,6 +3296,7 @@ def _create_s3_client(
3268
3296
signature_version = signature_version ,
3269
3297
s3 = s3_config ,
3270
3298
use_fips_endpoint = use_fips_endpoint ,
3299
+ retries = retries ,
3271
3300
)
3272
3301
s3 = session .create_client (
3273
3302
's3' ,
0 commit comments