diff options
author | Erik Johnston <erik@matrix.org> | 2016-04-08 14:09:56 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-04-08 14:09:56 +0100 |
commit | 79fc4ff6f9a0670d6fcb01b756500746445c5cae (patch) | |
tree | da5b2c0203892248fd86a6dd6e71fce198f62992 /tests | |
parent | Merge pull request #707 from matrix-org/markjh/remove_changed_presencelike_data (diff) | |
parent | Merge branch 'develop' of github.com:matrix-org/synapse into erikj/dns_cache (diff) | |
download | synapse-79fc4ff6f9a0670d6fcb01b756500746445c5cae.tar.xz |
Merge pull request #677 from matrix-org/erikj/dns_cache
Read from DNS cache if within TTL
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_dns.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/test_dns.py b/tests/test_dns.py index 637b1606f8..c394c57ee7 100644 --- a/tests/test_dns.py +++ b/tests/test_dns.py @@ -21,6 +21,8 @@ from mock import Mock from synapse.http.endpoint import resolve_service +from tests.utils import MockClock + class DnsTestCase(unittest.TestCase): @@ -63,14 +65,17 @@ class DnsTestCase(unittest.TestCase): self.assertEquals(servers[0].host, ip_address) @defer.inlineCallbacks - def test_from_cache(self): + def test_from_cache_expired_and_dns_fail(self): dns_client_mock = Mock() dns_client_mock.lookupService.return_value = defer.fail(error.DNSServerError()) service_name = "test_service.examle.com" + entry = Mock(spec_set=["expires"]) + entry.expires = 0 + cache = { - service_name: [object()] + service_name: [entry] } servers = yield resolve_service( @@ -83,6 +88,31 @@ class DnsTestCase(unittest.TestCase): self.assertEquals(servers, cache[service_name]) @defer.inlineCallbacks + def test_from_cache(self): + clock = MockClock() + + dns_client_mock = Mock(spec_set=['lookupService']) + dns_client_mock.lookupService = Mock(spec_set=[]) + + service_name = "test_service.examle.com" + + entry = Mock(spec_set=["expires"]) + entry.expires = 999999999 + + cache = { + service_name: [entry] + } + + servers = yield resolve_service( + service_name, dns_client=dns_client_mock, cache=cache, clock=clock, + ) + + self.assertFalse(dns_client_mock.lookupService.called) + + self.assertEquals(len(servers), 1) + self.assertEquals(servers, cache[service_name]) + + @defer.inlineCallbacks def test_empty_cache(self): dns_client_mock = Mock() |