diff options
author | Erik Johnston <erik@matrix.org> | 2016-04-06 10:12:30 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-04-06 10:12:30 +0100 |
commit | 11860637e116717efa14149f17d8b941d1e5db5e (patch) | |
tree | 9ba932ab2e8552e020b392faf51b9ac962786503 | |
parent | Allow clock to be passed in to func (diff) | |
download | synapse-11860637e116717efa14149f17d8b941d1e5db5e.tar.xz |
Tests
Diffstat (limited to '')
-rw-r--r-- | tests/test_dns.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/tests/test_dns.py b/tests/test_dns.py index e006ed1a59..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,14 @@ 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 = 999999999 + entry.expires = 0 cache = { service_name: [entry] @@ -86,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() |