diff --git a/aiohttp/connector.py b/aiohttp/connector.py index e2dd92cc293..9708ae4769c 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -9,7 +9,6 @@ from http.cookies import SimpleCookie from itertools import cycle, islice from time import monotonic -from types import MappingProxyType from . import hdrs, helpers from .client_exceptions import (ClientConnectionError, @@ -554,10 +553,6 @@ def __init__(self, ttl=None): def __contains__(self, host): return host in self._addrs - @property - def addrs(self): - return self._addrs - def add(self, host, addrs): self._addrs[host] = addrs self._addrs_rr[host] = cycle(addrs) @@ -705,11 +700,6 @@ def use_dns_cache(self): """True if local DNS caching is enabled.""" return self._use_dns_cache - @property - def cached_hosts(self): - """Read-only dict of cached DNS record.""" - return MappingProxyType(self._cached_hosts.addrs) - def clear_dns_cache(self, host=None, port=None): """Remove specified host/port or clear all dns local cache.""" if host is not None and port is not None: diff --git a/tests/test_connector.py b/tests/test_connector.py index 05eaf112771..1bf74f70b9b 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -1079,7 +1079,6 @@ def test_tcp_connector_ctor(loop): assert conn.use_dns_cache assert conn.family == 0 - assert conn.cached_hosts == {} def test_tcp_connector_ctor_fingerprint_valid(loop): @@ -1112,11 +1111,19 @@ def test_tcp_connector_clear_dns_cache(loop): conn._cached_hosts.add(('localhost', 123), hosts) conn._cached_hosts.add(('localhost', 124), hosts) conn.clear_dns_cache('localhost', 123) - assert ('localhost', 123) not in conn.cached_hosts + with pytest.raises(KeyError): + conn._cached_hosts.next_addrs(('localhost', 123)) + + assert conn._cached_hosts.next_addrs(('localhost', 124)) == hosts + + # Remove removed element is OK conn.clear_dns_cache('localhost', 123) - assert ('localhost', 123) not in conn.cached_hosts + with pytest.raises(KeyError): + conn._cached_hosts.next_addrs(('localhost', 123)) + conn.clear_dns_cache() - assert conn.cached_hosts == {} + with pytest.raises(KeyError): + conn._cached_hosts.next_addrs(('localhost', 124)) def test_tcp_connector_clear_dns_cache_bad_args(loop): @@ -1925,23 +1932,28 @@ class TestDNSCacheTable: def dns_cache_table(self): return _DNSCacheTable() - def test_addrs(self, dns_cache_table): + def test_next_addrs_basic(self, dns_cache_table): dns_cache_table.add('localhost', ['127.0.0.1']) dns_cache_table.add('foo', ['127.0.0.2']) - assert dns_cache_table.addrs == { - 'localhost': ['127.0.0.1'], - 'foo': ['127.0.0.2'] - } + + addrs = dns_cache_table.next_addrs('localhost') + assert addrs == ['127.0.0.1'] + addrs = dns_cache_table.next_addrs('foo') + assert addrs == ['127.0.0.2'] + with pytest.raises(KeyError): + dns_cache_table.next_addrs('no-such-host') def test_remove(self, dns_cache_table): dns_cache_table.add('localhost', ['127.0.0.1']) dns_cache_table.remove('localhost') - assert dns_cache_table.addrs == {} + with pytest.raises(KeyError): + dns_cache_table.next_addrs('localhost') def test_clear(self, dns_cache_table): dns_cache_table.add('localhost', ['127.0.0.1']) dns_cache_table.clear() - assert dns_cache_table.addrs == {} + with pytest.raises(KeyError): + dns_cache_table.next_addrs('localhost') def test_not_expired_ttl_None(self, dns_cache_table): dns_cache_table.add('localhost', ['127.0.0.1'])