Skip to content

[v2] Add test to ensure retries reuse request checksum #9591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/functional/botocore/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from botocore.config import Config
from botocore.exceptions import (
ClientError,
ConnectionError,
ParamValidationError,
UnsupportedS3AccesspointConfigurationError,
UnsupportedS3ConfigurationError,
Expand Down Expand Up @@ -2191,6 +2192,32 @@ def test_checksum_content_encoding(content_encoding, expected_header):
assert request_headers["Content-Encoding"] == expected_header


@mock.patch('botocore.endpoint.URLLib3Session.send')
@mock.patch('botocore.client.apply_request_checksum')
def test_retries_reuse_request_checksum(
mock_apply_request_checksum, mock_urllib3_session_send
):
# Force retry behavior.
mock_urllib3_session_send.side_effect = ConnectionError(error='Fake error')
op_kwargs = {
"Bucket": "mybucket",
"Key": "mykey",
"Body": b"foo",
"ChecksumAlgorithm": "CRC32",
}
s3 = _create_s3_client(
retries={
'max_attempts': 2,
}
)
with pytest.raises(ConnectionError):
s3.put_object(**op_kwargs)
# Ensure sending request was retried.
assert mock_urllib3_session_send.call_count == 2
# But request checksum was only calculated once.
assert mock_apply_request_checksum.call_count == 1


def _s3_addressing_test_cases():
# The default behavior for DNS compatible buckets
yield dict(
Expand Down Expand Up @@ -3255,6 +3282,7 @@ def _create_s3_client(
s3_config=None,
signature_version='s3v4',
use_fips_endpoint=None,
retries=None,
):
environ = {}
with mock.patch('os.environ', environ):
Expand All @@ -3268,6 +3296,7 @@ def _create_s3_client(
signature_version=signature_version,
s3=s3_config,
use_fips_endpoint=use_fips_endpoint,
retries=retries,
)
s3 = session.create_client(
's3',
Expand Down
Loading