Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 95931b2

Browse files
authored
Merge pull request #12 from hanula/hotfix/Switchable_DNS_cache
Hotfix/switchable dns cache
2 parents 223ae8f + 2335481 commit 95931b2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

elasticsearch_async/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class AIOHttpConnection(Connection):
1313
def __init__(self, host='localhost', port=9200, http_auth=None,
1414
use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
15-
client_key=None, loop=None, **kwargs):
15+
client_key=None, loop=None, use_dns_cache=True, **kwargs):
1616
super().__init__(host=host, port=port, **kwargs)
1717

1818
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,
3030
loop=self.loop,
3131
verify_ssl=verify_certs,
3232
conn_timeout=self.timeout,
33-
33+
use_dns_cache=use_dns_cache,
3434
)
3535
)
3636

test_elasticsearch_async/test_connection.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def test_info(connection):
1919
assert status == 200
2020
assert {'body': '', 'method': 'GET', 'params': {}, 'path': '/'} == data
2121

22-
def test_auth_is_set_correctly():
23-
connection = AIOHttpConnection(http_auth=('user', 'secret'))
22+
def test_auth_is_set_correctly(event_loop):
23+
connection = AIOHttpConnection(http_auth=('user', 'secret'), loop=event_loop)
2424
assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret')
2525

26-
connection = AIOHttpConnection(http_auth='user:secret')
26+
connection = AIOHttpConnection(http_auth='user:secret', loop=event_loop)
2727
assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret')
2828

2929
@mark.asyncio
@@ -64,3 +64,13 @@ def slow_request():
6464

6565
with raises(ConnectionTimeout):
6666
yield from connection.perform_request('GET', '/_search', timeout=0.0001)
67+
68+
69+
def test_dns_cache_is_enabled_by_default(event_loop):
70+
connection = AIOHttpConnection(loop=event_loop)
71+
assert connection.session.connector.use_dns_cache is True
72+
73+
74+
def test_dns_cache_can_be_disabled(event_loop):
75+
connection = AIOHttpConnection(loop=event_loop, use_dns_cache=False)
76+
assert connection.session.connector.use_dns_cache is False

0 commit comments

Comments
 (0)