From f109ad846d0f2c9dc8b918fd6d1d6fcb6788e044 Mon Sep 17 00:00:00 2001 From: Sebastian Hanula Date: Mon, 13 Feb 2017 22:28:21 +0100 Subject: [PATCH 1/3] Bump version to 2.0.0. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f03ee49..8c3a4bd 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from os.path import join, dirname from setuptools import setup, find_packages -VERSION = (1, 0, 0) +VERSION = (2, 0, 0) __version__ = VERSION __versionstr__ = '.'.join(map(str, VERSION)) @@ -12,7 +12,7 @@ install_requires = [ 'aiohttp', - 'elasticsearch>=2.4.0', + 'elasticsearch>=2.4.0,<3.0.0', ] tests_require = [ From bc98d3aed76ea76118647387604624a1121995e3 Mon Sep 17 00:00:00 2001 From: Sebastian Hanula Date: Mon, 13 Feb 2017 22:30:22 +0100 Subject: [PATCH 2/3] Test `AIOHttpConnection` auth with explicit event loop. --- test_elasticsearch_async/test_connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test_elasticsearch_async/test_connection.py b/test_elasticsearch_async/test_connection.py index 33c726d..23e268d 100644 --- a/test_elasticsearch_async/test_connection.py +++ b/test_elasticsearch_async/test_connection.py @@ -19,11 +19,11 @@ def test_info(connection): assert status == 200 assert {'body': '', 'method': 'GET', 'params': {}, 'path': '/'} == data -def test_auth_is_set_correctly(): - connection = AIOHttpConnection(http_auth=('user', 'secret')) +def test_auth_is_set_correctly(event_loop): + connection = AIOHttpConnection(http_auth=('user', 'secret'), loop=event_loop) assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret') - connection = AIOHttpConnection(http_auth='user:secret') + connection = AIOHttpConnection(http_auth='user:secret', loop=event_loop) assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret') @mark.asyncio From 98168633f8d5c138202d63694209beaae6b9a6ea Mon Sep 17 00:00:00 2001 From: Sebastian Hanula Date: Mon, 13 Feb 2017 16:04:54 +0100 Subject: [PATCH 3/3] Add `use_dns_cache` param to `AIOHttpConnection` to allow disabling DNS cache. --- elasticsearch_async/connection.py | 4 ++-- test_elasticsearch_async/test_connection.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/elasticsearch_async/connection.py b/elasticsearch_async/connection.py index c228d3f..420b2f7 100644 --- a/elasticsearch_async/connection.py +++ b/elasticsearch_async/connection.py @@ -12,7 +12,7 @@ class AIOHttpConnection(Connection): def __init__(self, host='localhost', port=9200, http_auth=None, use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None, - client_key=None, loop=None, **kwargs): + client_key=None, loop=None, use_dns_cache=True, **kwargs): super().__init__(host=host, port=port, **kwargs) self.loop = asyncio.get_event_loop() if loop is None else loop @@ -30,7 +30,7 @@ def __init__(self, host='localhost', port=9200, http_auth=None, loop=self.loop, verify_ssl=verify_certs, conn_timeout=self.timeout, - + use_dns_cache=use_dns_cache, ) ) diff --git a/test_elasticsearch_async/test_connection.py b/test_elasticsearch_async/test_connection.py index 23e268d..f6392a4 100644 --- a/test_elasticsearch_async/test_connection.py +++ b/test_elasticsearch_async/test_connection.py @@ -64,3 +64,13 @@ def slow_request(): with raises(ConnectionTimeout): yield from connection.perform_request('GET', '/_search', timeout=0.0001) + + +def test_dns_cache_is_enabled_by_default(event_loop): + connection = AIOHttpConnection(loop=event_loop) + assert connection.session.connector.use_dns_cache is True + + +def test_dns_cache_can_be_disabled(event_loop): + connection = AIOHttpConnection(loop=event_loop, use_dns_cache=False) + assert connection.session.connector.use_dns_cache is False