Skip to content

Commit

Permalink
wrap all the tests that can time out
Browse files Browse the repository at this point in the history
  • Loading branch information
rthalley committed Oct 12, 2024
1 parent e9da624 commit d933768
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
28 changes: 28 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def setUp(self):
def async_run(self, afunc):
return asyncio.run(afunc())

@tests.util.retry_on_timeout
def testResolve(self):
async def run():
answer = await dns.asyncresolver.resolve("dns.google.", "A")
Expand All @@ -196,6 +197,7 @@ async def run():
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testResolveAddress(self):
async def run():
return await dns.asyncresolver.resolve_address("8.8.8.8")
Expand All @@ -204,6 +206,7 @@ async def run():
dnsgoogle = dns.name.from_text("dns.google.")
self.assertEqual(answer[0].target, dnsgoogle)

@tests.util.retry_on_timeout
def testResolveName(self):
async def run1():
return await dns.asyncresolver.resolve_name("dns.google.")
Expand Down Expand Up @@ -250,6 +253,7 @@ async def run5():
with self.assertRaises(dns.resolver.NoAnswer):
self.async_run(run5)

@tests.util.retry_on_timeout
def testCanonicalNameNoCNAME(self):
cname = dns.name.from_text("www.google.com")

Expand All @@ -258,6 +262,7 @@ async def run():

self.assertEqual(self.async_run(run), cname)

@tests.util.retry_on_timeout
def testCanonicalNameCNAME(self):
name = dns.name.from_text("www.dnspython.org")
cname = dns.name.from_text("dmfrjf4ips8xa.cloudfront.net")
Expand All @@ -270,6 +275,7 @@ async def run():
@unittest.skipIf(
_systemd_resolved_present or _is_docker, "systemd-resolved or docker in use"
)
@tests.util.retry_on_timeout
def testCanonicalNameDangling(self):
name = dns.name.from_text("dangling-cname.dnspython.org")
cname = dns.name.from_text("dangling-target.dnspython.org")
Expand All @@ -279,6 +285,7 @@ async def run():

self.assertEqual(self.async_run(run), cname)

@tests.util.retry_on_timeout
def testZoneForName1(self):
async def run():
name = dns.name.from_text("www.dnspython.org.")
Expand All @@ -288,6 +295,7 @@ async def run():
zname = self.async_run(run)
self.assertEqual(zname, ezname)

@tests.util.retry_on_timeout
def testZoneForName2(self):
async def run():
name = dns.name.from_text("a.b.www.dnspython.org.")
Expand All @@ -297,6 +305,7 @@ async def run():
zname = self.async_run(run)
self.assertEqual(zname, ezname)

@tests.util.retry_on_timeout
def testZoneForName3(self):
async def run():
name = dns.name.from_text("dnspython.org.")
Expand All @@ -317,6 +326,7 @@ async def run():

self.assertRaises(dns.resolver.NotAbsolute, bad)

@tests.util.retry_on_timeout
def testQueryUDP(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -334,6 +344,7 @@ async def run():
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryUDPWithSocket(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -358,6 +369,7 @@ async def run():
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryTCP(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -375,6 +387,7 @@ async def run():
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryTCPWithSocket(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand Down Expand Up @@ -403,6 +416,7 @@ async def run():
self.assertTrue("8.8.4.4" in seen)

@unittest.skipIf(not _ssl_available, "SSL not available")
@tests.util.retry_on_timeout
def testQueryTLS(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -421,6 +435,7 @@ async def run():
self.assertTrue("8.8.4.4" in seen)

@unittest.skipIf(not _ssl_available, "SSL not available")
@tests.util.retry_on_timeout
def testQueryTLSWithContext(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -443,6 +458,7 @@ async def run():
self.assertTrue("8.8.4.4" in seen)

@unittest.skipIf(not _ssl_available, "SSL not available")
@tests.util.retry_on_timeout
def testQueryTLSWithSocket(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand Down Expand Up @@ -474,6 +490,7 @@ async def run():
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryUDPFallback(self):
for address in query_addresses:
qname = dns.name.from_text(".")
Expand All @@ -485,6 +502,7 @@ async def run():
(_, tcp) = self.async_run(run)
self.assertTrue(tcp)

@tests.util.retry_on_timeout
def testQueryUDPFallbackNoFallback(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -496,6 +514,7 @@ async def run():
(_, tcp) = self.async_run(run)
self.assertFalse(tcp)

@tests.util.retry_on_timeout
def testUDPReceiveQuery(self):
async def run():
async with await self.backend.make_socket(
Expand Down Expand Up @@ -536,6 +555,7 @@ def run():
self.assertRaises(dns.exception.Timeout, run)

@unittest.skipIf(not dns.query._have_httpx, "httpx not available")
@tests.util.retry_on_timeout
def testDOHGetRequest(self):
async def run():
nameserver_url = random.choice(KNOWN_ANYCAST_DOH_RESOLVER_URLS)
Expand All @@ -548,6 +568,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not dns.query._have_httpx, "httpx not available")
@tests.util.retry_on_timeout
def testDOHPostRequest(self):
async def run():
nameserver_url = random.choice(KNOWN_ANYCAST_DOH_RESOLVER_URLS)
Expand All @@ -560,6 +581,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not dns.quic.have_quic, "aioquic not available")
@tests.util.retry_on_timeout
def testDoH3GetRequest(self):
async def run():
nameserver_url = random.choice(KNOWN_ANYCAST_DOH3_RESOLVER_URLS)
Expand All @@ -577,6 +599,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not dns.quic.have_quic, "aioquic not available")
@tests.util.retry_on_timeout
def TestDoH3PostRequest(self):
async def run():
nameserver_url = random.choice(KNOWN_ANYCAST_DOH3_RESOLVER_URLS)
Expand All @@ -594,6 +617,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not dns.quic.have_quic, "aioquic not available")
@tests.util.retry_on_timeout
def TestDoH3QueryIP(self):
async def run():
nameserver_ip = "8.8.8.8"
Expand All @@ -610,6 +634,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not dns.query._have_httpx, "httpx not available")
@tests.util.retry_on_timeout
def testResolverDOH(self):
async def run():
res = dns.asyncresolver.Resolver(configure=False)
Expand All @@ -622,6 +647,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not tests.util.have_ipv4(), "IPv4 not reachable")
@tests.util.retry_on_timeout
def testResolveAtAddress(self):
async def run():
answer = await dns.asyncresolver.resolve_at("8.8.8.8", "dns.google.", "A")
Expand All @@ -632,6 +658,7 @@ async def run():
self.async_run(run)

@unittest.skipIf(not tests.util.have_ipv4(), "IPv4 not reachable")
@tests.util.retry_on_timeout
def testResolveAtName(self):
async def run():
answer = await dns.asyncresolver.resolve_at(
Expand Down Expand Up @@ -661,6 +688,7 @@ def setUp(self):
def async_run(self, afunc):
return asyncio.run(afunc())

@tests.util.retry_on_timeout
def testUseAfterTimeout(self):
# Test #843 fix.
async def run():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ddr.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

import asyncio
import time

import pytest

import dns.asyncbackend
import dns.asyncresolver
import dns.resolver
import dns.nameserver

import dns.resolver
import tests.util


@pytest.mark.skipif(
not tests.util.is_internet_reachable(), reason="Internet not reachable"
)
@tests.util.retry_on_timeout
def test_basic_ddr_sync():
for nameserver in ["1.1.1.1", "8.8.8.8"]:
res = dns.resolver.Resolver(configure=False)
Expand All @@ -29,6 +28,7 @@ def test_basic_ddr_sync():
@pytest.mark.skipif(
not tests.util.is_internet_reachable(), reason="Internet not reachable"
)
@tests.util.retry_on_timeout
def test_basic_ddr_async():
async def run():
dns.asyncbackend._default_backend = None
Expand Down
12 changes: 12 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Server(object):

@unittest.skipIf(not tests.util.is_internet_reachable(), "Internet not reachable")
class QueryTests(unittest.TestCase):
@tests.util.retry_on_timeout
def testQueryUDP(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -79,6 +80,7 @@ def testQueryUDP(self):
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryUDPWithSocket(self):
for address in query_addresses:
with socket.socket(
Expand All @@ -96,6 +98,7 @@ def testQueryUDPWithSocket(self):
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryTCP(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -109,6 +112,7 @@ def testQueryTCP(self):
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def testQueryTCPWithSocket(self):
for address in query_addresses:
with socket.socket(
Expand All @@ -130,6 +134,7 @@ def testQueryTCPWithSocket(self):
self.assertTrue("8.8.4.4" in seen)

@unittest.skipUnless(have_ssl, "No SSL support")
@tests.util.retry_on_timeout
def testQueryTLS(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -144,6 +149,7 @@ def testQueryTLS(self):
self.assertTrue("8.8.4.4" in seen)

@unittest.skipUnless(have_ssl, "No SSL support")
@tests.util.retry_on_timeout
def testQueryTLSWithContext(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -160,6 +166,7 @@ def testQueryTLSWithContext(self):
self.assertTrue("8.8.4.4" in seen)

@unittest.skipUnless(have_ssl, "No SSL support")
@tests.util.retry_on_timeout
def testQueryTLSWithSocket(self):
for address in query_addresses:
with socket.socket(
Expand All @@ -186,6 +193,7 @@ def testQueryTLSWithSocket(self):
self.assertTrue("8.8.4.4" in seen)

@unittest.skipUnless(have_ssl, "No SSL support")
@tests.util.retry_on_timeout
def testQueryTLSwithPadding(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
Expand All @@ -206,13 +214,15 @@ def testQueryTLSwithPadding(self):
has_pad = True
self.assertTrue(has_pad)

@tests.util.retry_on_timeout
def testQueryUDPFallback(self):
for address in query_addresses:
qname = dns.name.from_text(".")
q = dns.message.make_query(qname, dns.rdatatype.DNSKEY)
(_, tcp) = dns.query.udp_with_fallback(q, address, timeout=4)
self.assertTrue(tcp)

@tests.util.retry_on_timeout
def testQueryUDPFallbackWithSocket(self):
for address in query_addresses:
af = dns.inet.af_for_address(address)
Expand All @@ -230,13 +240,15 @@ def testQueryUDPFallbackWithSocket(self):
)
self.assertTrue(tcp)

@tests.util.retry_on_timeout
def testQueryUDPFallbackNoFallback(self):
for address in query_addresses:
qname = dns.name.from_text("dns.google.")
q = dns.message.make_query(qname, dns.rdatatype.A)
(_, tcp) = dns.query.udp_with_fallback(q, address, timeout=2)
self.assertFalse(tcp)

@tests.util.retry_on_timeout
def testUDPReceiveQuery(self):
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as listener:
listener.bind(("127.0.0.1", 0))
Expand Down
Loading

0 comments on commit d933768

Please sign in to comment.