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], timeout=3, loop=event_loop) # second request should not timeout just because there isn't a # connector available assert len(pending) == 2 finally: task1.cancel() task2.cancel()
def test_connector_timeout(loop): server = AIOServer() session = AioSession(loop=loop) config = AioConfig(max_pool_connections=1, connect_timeout=1, retries={'max_attempts': 0}) s3_client = session.create_client('s3', config=config, endpoint_url=server.endpoint_url, aws_secret_access_key='xxx', aws_access_key_id='xxx') try: server.wait_until_up() @asyncio.coroutine def get_and_wait(): yield from s3_client.get_object(Bucket='foo', Key='bar') yield from asyncio.sleep(100) # this should not raise as we won't have any issues connecting to the task1 = asyncio.Task(get_and_wait(), loop=loop) task2 = asyncio.Task(get_and_wait(), loop=loop) try: done, pending = yield from asyncio.wait([task1, task2], timeout=3, loop=loop) # second request should not timeout just because there isn't a # connector available assert len(pending) == 2 finally: task1.cancel() task2.cancel() finally: s3_client.close() yield from server.stop()
async def test_retry(session: AioSession, caplog): caplog.set_level(logging.DEBUG) config = AioConfig( connect_timeout=1, read_timeout=1, # this goes through a slightly different codepath than regular retries retries={ "mode": "standard", "total_max_attempts": 3, }, ) async with session.create_client( 's3', config=config, aws_secret_access_key="xxx", aws_access_key_id="xxx", endpoint_url='http://localhost:7878') as client: with pytest.raises(EndpointConnectionError): await client.get_object(Bucket='foo', Key='bar') assert 'sleeping for' in caplog.text
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_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(ReadTimeoutError): resp = await s3_client.get_object(Bucket='foo', Key='bar') await resp["Body"].read()
# have to use discovery to load platform. for notify_config in conf[CONF_NOTIFY]: hass.async_create_task( discovery.async_load_platform(hass, Platform.NOTIFY, DOMAIN, notify_config, config)) return validation async def _validate_aws_credentials(hass, credential): """Validate AWS credential config.""" aws_config = credential.copy() del aws_config[CONF_NAME] del aws_config[CONF_VALIDATE] if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None: session = AioSession(profile=profile) del aws_config[CONF_PROFILE_NAME] if CONF_ACCESS_KEY_ID in aws_config: del aws_config[CONF_ACCESS_KEY_ID] if CONF_SECRET_ACCESS_KEY in aws_config: del aws_config[CONF_SECRET_ACCESS_KEY] else: session = AioSession() if credential[CONF_VALIDATE]: async with session.create_client("iam", **aws_config) as client: await client.get_user() return session