Skip to content

Commit 38b4347

Browse files
committed
Add tests
1 parent 38a002d commit 38b4347

File tree

5 files changed

+112
-7
lines changed

5 files changed

+112
-7
lines changed

awscli/customizations/s3/factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import awscrt.s3
1616
from botocore.client import Config
1717
from botocore.httpsession import DEFAULT_CA_BUNDLE
18+
from s3transfer.constants import GB
1819
from s3transfer.crt import (
1920
BotocoreCRTCredentialsWrapper,
2021
BotocoreCRTRequestSerializer,
@@ -142,7 +143,8 @@ def _create_crt_client(self, params, runtime_config):
142143
if (val := runtime_config.get('should_stream')) is not None:
143144
fio_options['should_stream'] = val
144145
if (val := runtime_config.get('disk_throughput')) is not None:
145-
fio_options['disk_throughput_gbps'] = val
146+
# Convert bytes to gigabits.
147+
fio_options['disk_throughput_gbps'] = val * 8 / GB
146148
if (val := runtime_config.get('direct_io')) is not None:
147149
fio_options['direct_io'] = val
148150
create_crt_client_kwargs['fio_options'] = fio_options

awscli/s3transfer/crt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from botocore.exceptions import NoCredentialsError
4646
from botocore.useragent import register_feature_id
4747
from botocore.utils import ArnParser, InvalidArnException, is_s3express_bucket
48-
from s3transfer.constants import FULL_OBJECT_CHECKSUM_ARGS, GB, MB
48+
from s3transfer.constants import FULL_OBJECT_CHECKSUM_ARGS, MB
4949
from s3transfer.exceptions import TransferNotDoneError
5050
from s3transfer.futures import BaseTransferFuture, BaseTransferMeta
5151
from s3transfer.utils import CallArgs, OSUtils, get_callbacks
@@ -155,9 +155,9 @@ def create_s3_crt_client(
155155
target_gbps = _get_crt_throughput_target_gbps(
156156
provided_throughput_target_bytes=target_throughput
157157
)
158-
fio_options = fio_options or {}
159-
if disk_throughput := fio_options.get('disk_throughput_gbps'):
160-
fio_options['disk_throughput_gbps'] = disk_throughput * 8 / GB
158+
crt_fio_options = None
159+
if fio_options:
160+
crt_fio_options = S3FileIoOptions(**fio_options)
161161
return S3Client(
162162
bootstrap=bootstrap,
163163
region=region,
@@ -167,7 +167,7 @@ def create_s3_crt_client(
167167
tls_connection_options=tls_connection_options,
168168
throughput_target_gbps=target_gbps,
169169
enable_s3express=True,
170-
fio_options=S3FileIoOptions(**fio_options),
170+
fio_options=crt_fio_options,
171171
)
172172

173173

tests/unit/customizations/s3/test_factory.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import awscrt.s3
1414
import pytest
1515
import s3transfer.crt
16-
from awscrt.s3 import S3RequestTlsMode
16+
from awscrt.s3 import S3FileIoOptions, S3RequestTlsMode
1717
from botocore.config import Config
1818
from botocore.credentials import Credentials
1919
from botocore.httpsession import DEFAULT_CA_BUNDLE
@@ -483,6 +483,27 @@ def test_target_bandwidth_configure_for_crt_manager(self, mock_crt_client):
483483
self.assert_is_crt_manager(transfer_manager)
484484
self.assert_expected_throughput_target_gbps(mock_crt_client, 8)
485485

486+
@mock.patch('s3transfer.crt.S3Client')
487+
def test_fio_options_configure_for_crt_manager(self, mock_crt_client):
488+
self.runtime_config = self.get_runtime_config(
489+
preferred_transfer_client='crt',
490+
should_stream=True,
491+
disk_throughput='5GB/s',
492+
direct_io=True,
493+
)
494+
transfer_manager = self.factory.create_transfer_manager(
495+
self.params, self.runtime_config
496+
)
497+
expected_fio_options = S3FileIoOptions(
498+
should_stream=True,
499+
disk_throughput_gbps=40.0,
500+
direct_io=True,
501+
)
502+
self.assert_is_crt_manager(transfer_manager)
503+
self.assertEqual(
504+
mock_crt_client.call_args[1]['fio_options'], expected_fio_options
505+
)
506+
486507
@mock.patch('s3transfer.crt.get_recommended_throughput_target_gbps')
487508
@mock.patch('s3transfer.crt.S3Client')
488509
def test_target_bandwidth_uses_crt_recommended_throughput(

tests/unit/customizations/s3/test_transferconfig.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def test_set_preferred_transfer_client(self, provided, resolved):
103103
('target_bandwidth', '1000', 1000),
104104
('target_bandwidth', '1000B/s', 1000),
105105
('target_bandwidth', '8000b/s', 1000),
106+
# disk_throughput cases
107+
('disk_throughput', '1MB/s', 1024 * 1024),
108+
('disk_throughput', '10Mb/s', 10 * 1024 * 1024 / 8),
109+
('disk_throughput', '1000', 1000),
110+
('disk_throughput', '1000B/s', 1000),
111+
('disk_throughput', '8000b/s', 1000),
106112
],
107113
)
108114
def test_rate_conversions(self, config_name, provided, expected):
@@ -127,6 +133,13 @@ def test_rate_conversions(self, config_name, provided, expected):
127133
('target_bandwidth', '100/s'),
128134
('target_bandwidth', ''),
129135
('target_bandwidth', 'value-with-no-digits'),
136+
# disk_throughput cases
137+
('disk_throughput', '1MB'),
138+
('disk_throughput', '1B'),
139+
('disk_throughput', '1b'),
140+
('disk_throughput', '100/s'),
141+
('disk_throughput', ''),
142+
('disk_throughput', 'value-with-no-digits'),
130143
],
131144
)
132145
def test_invalid_rate_values(self, config_name, provided):
@@ -138,6 +151,22 @@ def test_validates_preferred_transfer_client_choices(self):
138151
with pytest.raises(transferconfig.InvalidConfigError):
139152
self.build_config_with(preferred_transfer_client='not-supported')
140153

154+
@pytest.mark.parametrize(
155+
'attr,val,expected',
156+
[
157+
('should_stream', 'true', True),
158+
('should_stream', 'false', False),
159+
('should_stream', None, None),
160+
('direct_io', 'true', True),
161+
('direct_io', 'false', False),
162+
('direct_io', None, None),
163+
],
164+
)
165+
def test_convert_booleans(self, attr, val, expected):
166+
params = {attr: val}
167+
runtime_config = self.build_config_with(**params)
168+
assert runtime_config[attr] == expected
169+
141170

142171
class TestConvertToS3TransferConfig:
143172
def test_convert(self):

tests/unit/s3transfer/test_crt.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from botocore.credentials import Credentials, ReadOnlyCredentials
1717
from botocore.exceptions import ClientError, NoCredentialsError
1818
from botocore.session import Session
19+
from s3transfer.constants import GB
1920
from s3transfer.exceptions import TransferNotDoneError
2021
from s3transfer.utils import CallArgs
2122

@@ -365,3 +366,55 @@ def test_target_throughput(
365366
def test_always_enables_s3express(self, mock_s3_crt_client):
366367
s3transfer.crt.create_s3_crt_client('us-west-2')
367368
assert mock_s3_crt_client.call_args[1]['enable_s3express'] is True
369+
370+
@pytest.mark.parametrize(
371+
'fio_options,should_stream,disk_throughput,direct_io',
372+
[
373+
({'should_stream': True}, True, 0.0, False),
374+
({'disk_throughput_gbps': 8}, False, 8, False),
375+
({'direct_io': True}, False, 0.0, True),
376+
(
377+
{'should_stream': True, 'disk_throughput_gbps': 8},
378+
True,
379+
8,
380+
False,
381+
),
382+
({'should_stream': True, 'direct_io': True}, True, 0.0, True),
383+
({'disk_throughput_gbps': 8, 'direct_io': True}, False, 8, True),
384+
(
385+
{
386+
'should_stream': True,
387+
'disk_throughput_gbps': 8,
388+
'direct_io': True,
389+
},
390+
True,
391+
8,
392+
True,
393+
),
394+
],
395+
)
396+
def test_fio_options(
397+
self,
398+
fio_options,
399+
should_stream,
400+
disk_throughput,
401+
direct_io,
402+
mock_s3_crt_client,
403+
):
404+
params = {'fio_options': fio_options}
405+
s3transfer.crt.create_s3_crt_client(
406+
'us-west-2',
407+
**params,
408+
)
409+
assert (
410+
mock_s3_crt_client.call_args[1]['fio_options'].should_stream
411+
is should_stream
412+
)
413+
assert (
414+
mock_s3_crt_client.call_args[1]['fio_options'].disk_throughput_gbps
415+
== disk_throughput
416+
)
417+
assert (
418+
mock_s3_crt_client.call_args[1]['fio_options'].direct_io
419+
is direct_io
420+
)

0 commit comments

Comments
 (0)