Skip to content

Commit f78d9e5

Browse files
authored
[v2] Add test to ensure retries reuse request checksum (#9591)
1 parent 8564f88 commit f78d9e5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/functional/botocore/test_s3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from botocore.config import Config
2020
from botocore.exceptions import (
2121
ClientError,
22+
ConnectionError,
2223
ParamValidationError,
2324
UnsupportedS3AccesspointConfigurationError,
2425
UnsupportedS3ConfigurationError,
@@ -2191,6 +2192,32 @@ def test_checksum_content_encoding(content_encoding, expected_header):
21912192
assert request_headers["Content-Encoding"] == expected_header
21922193

21932194

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+
21942221
def _s3_addressing_test_cases():
21952222
# The default behavior for DNS compatible buckets
21962223
yield dict(
@@ -3255,6 +3282,7 @@ def _create_s3_client(
32553282
s3_config=None,
32563283
signature_version='s3v4',
32573284
use_fips_endpoint=None,
3285+
retries=None,
32583286
):
32593287
environ = {}
32603288
with mock.patch('os.environ', environ):
@@ -3268,6 +3296,7 @@ def _create_s3_client(
32683296
signature_version=signature_version,
32693297
s3=s3_config,
32703298
use_fips_endpoint=use_fips_endpoint,
3299+
retries=retries,
32713300
)
32723301
s3 = session.create_client(
32733302
's3',

0 commit comments

Comments
 (0)