async def performance_aiosonic(url, concurrency, pool_cls=None, timeouts=None): """Test aiohttp performance.""" return await timeit_coro(aiosonic.get, url, connector=TCPConnector(pool_size=concurrency, pool_cls=pool_cls), timeouts=timeouts)
async def test_get_http2(http2_serv): """Test simple get to node http2 server.""" url = http2_serv connector = TCPConnector(timeouts=Timeouts(sock_connect=3, sock_read=4)) res = await aiosonic.get(url, connector=connector, verify=False) assert res.status_code == 200 assert 'Hello World' == await res.text()
async def test_pool_acquire_timeout(app, aiohttp_server, mocker): """Test pool acquirere timeout.""" server = await aiohttp_server(app) url = 'http://localhost:%d/slow_request' % server.port connector = TCPConnector(pool_size=1, timeouts=Timeouts(pool_acquire=0.3)) with pytest.raises(ConnectionPoolAcquireTimeout): await asyncio.gather( aiosonic.get(url, connector=connector), aiosonic.get(url, connector=connector), ) await server.close()
async def test_connect_timeout(mocker): """Test connect timeout.""" url = 'http://localhost:1234' async def long_connect(*_args, **_kwargs): await asyncio.sleep(3) _connect = mocker.patch('aiosonic.connection.Connection._connect') _connect.return_value = long_connect() with pytest.raises(ConnectTimeout): await aiosonic.get( url, connector=TCPConnector(timeouts=Timeouts(sock_connect=0.2)))
async def test_get_google_http2(): """Test simple get.""" url = 'https://www.google.com' connector = TCPConnector( timeouts=Timeouts(sock_connect=3, sock_read=4)) res = await aiosonic.get(url, connector=connector, headers={ 'user-agent': ( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 ' 'Safari/537.36') }) assert res.status_code == 200 assert '<title>Google</title>' in await res.text()