Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_connector_timeout(event_loop):
session = AioSession(loop=event_loop)
config = AioConfig(max_pool_connections=1, connect_timeout=1,
retries={'max_attempts': 0})
async with AIOServer() as server, \
session.create_client('s3', config=config,
endpoint_url=server.endpoint_url,
aws_secret_access_key='xxx',
aws_access_key_id='xxx') as s3_client:
async def get_and_wait():
await s3_client.get_object(Bucket='foo', Key='bar')
await asyncio.sleep(100)
task1 = asyncio.Task(get_and_wait(), loop=event_loop)
task2 = asyncio.Task(get_and_wait(), loop=event_loop)
try:
done, pending = await asyncio.wait([task1, task2],
async def test_connector_timeout(event_loop):
session = AioSession(loop=event_loop)
config = AioConfig(max_pool_connections=1, connect_timeout=1,
retries={'max_attempts': 0})
async with AIOServer() as server, \
session.create_client('s3', config=config,
endpoint_url=server.endpoint_url,
aws_secret_access_key='xxx',
aws_access_key_id='xxx') as s3_client:
async def get_and_wait():
await s3_client.get_object(Bucket='foo', Key='bar')
await asyncio.sleep(100)
task1 = asyncio.Task(get_and_wait(), loop=event_loop)
task2 = asyncio.Task(get_and_wait(), loop=event_loop)
try:
connector_args = dict(force_close="1")
AioConfig(connector_args)
with pytest.raises(ParamValidationError):
# wrong type
connector_args = dict(ssl_context="1")
AioConfig(connector_args)
with pytest.raises(ParamValidationError):
# invalid key
connector_args = dict(foo="1")
AioConfig(connector_args)
# test merge
cfg = Config(read_timeout=75)
aio_cfg = AioConfig({'keepalive_timeout': 75})
aio_cfg.merge(cfg)
assert cfg.read_timeout == 75
assert aio_cfg.connector_args['keepalive_timeout'] == 75
async def test_connector_timeout2(event_loop):
session = AioSession(loop=event_loop)
config = AioConfig(max_pool_connections=1, connect_timeout=1,
read_timeout=1, retries={'max_attempts': 0})
async with AIOServer() as server, \
session.create_client('s3', config=config,
endpoint_url=server.endpoint_url,
aws_secret_access_key='xxx',
aws_access_key_id='xxx') as s3_client:
with pytest.raises(asyncio.TimeoutError):
resp = await s3_client.get_object(Bucket='foo', Key='bar')
await resp["Body"].read()
async def test_iter_chunks_with_leftover():
body = AsyncBytesIO(b'abcde')
stream = response.StreamingBody(body, content_length=5)
chunks = await _tolist(stream.iter_chunks(chunk_size=2))
assert chunks, [b'ab', b'cd' == b'e']
async def test_default_iter_behavior():
body = AsyncBytesIO(b'a' * 2048)
stream = response.StreamingBody(body, content_length=2048)
chunks = await _tolist(stream)
assert len(chunks) == 2
assert chunks, [b'a' * 1024 == b'a' * 1024]
async def test_streaming_body_with_single_read():
body = AsyncBytesIO(b'123456789')
stream = response.StreamingBody(body, content_length=10)
with pytest.raises(IncompleteReadError):
await stream.read()
async def test_streaming_line_abstruse_newline_standard():
for chunk_size in range(1, 30):
body = AsyncBytesIO(b'1234567890\r\n1234567890\r\n12345\r\n')
stream = response.StreamingBody(body, content_length=31)
await assert_lines(
stream.iter_lines(chunk_size),
[b'1234567890', b'1234567890', b'12345'],
)
async def test_iter_chunks_single_byte():
body = AsyncBytesIO(b'abcde')
stream = response.StreamingBody(body, content_length=5)
chunks = await _tolist(stream.iter_chunks(chunk_size=1))
assert chunks, [b'a', b'b', b'c', b'd' == b'e']
async def test_streaming_body_is_an_iterator():
body = AsyncBytesIO(b'a' * 1024 + b'b' * 1024 + b'c' * 2)
stream = response.StreamingBody(body, content_length=2050)
assert b'a' * 1024 == await stream.__anext__()
assert b'b' * 1024 == await stream.__anext__()
assert b'c' * 2 == await stream.__anext__()
with pytest.raises(StopAsyncIteration):
await stream.__anext__()