Skip to content

Commit

Permalink
Retry on test timeout (#1146)
Browse files Browse the repository at this point in the history
wrap all the tests that can time out
  • Loading branch information
rthalley authored Oct 12, 2024
1 parent 91d329a commit 6c2c566
Show file tree
Hide file tree
Showing 6 changed files with 87 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
11 changes: 11 additions & 0 deletions tests/test_doh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import socket
import unittest

import dns.exception

try:
import ssl

Expand Down Expand Up @@ -88,6 +90,7 @@ def setUp(self):
def tearDown(self):
self.session.close()

@tests.util.retry_on_timeout
def test_get_request(self):
nameserver_url = random.choice(KNOWN_ANYCAST_DOH_RESOLVER_URLS)
q = dns.message.make_query("example.com.", dns.rdatatype.A)
Expand All @@ -101,6 +104,7 @@ def test_get_request(self):
)
self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def test_post_request(self):
nameserver_url = random.choice(KNOWN_ANYCAST_DOH_RESOLVER_URLS)
q = dns.message.make_query("example.com.", dns.rdatatype.A)
Expand All @@ -114,6 +118,7 @@ def test_post_request(self):
)
self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def test_build_url_from_ip(self):
self.assertTrue(resolver_v4_addresses or resolver_v6_addresses)
if resolver_v4_addresses:
Expand Down Expand Up @@ -159,12 +164,14 @@ def test_build_url_from_ip(self):
# )
# self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def test_new_session(self):
nameserver_url = random.choice(KNOWN_ANYCAST_DOH_RESOLVER_URLS)
q = dns.message.make_query("example.com.", dns.rdatatype.A)
r = dns.query.https(q, nameserver_url, timeout=4)
self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def test_resolver(self):
res = dns.resolver.Resolver(configure=False)
res.nameservers = ["https://dns.google/dns-query"]
Expand All @@ -173,6 +180,7 @@ def test_resolver(self):
self.assertTrue("8.8.8.8" in seen)
self.assertTrue("8.8.4.4" in seen)

@tests.util.retry_on_timeout
def test_padded_get(self):
nameserver_url = random.choice(KNOWN_PAD_AWARE_DOH_RESOLVER_URLS)
q = dns.message.make_query("example.com.", dns.rdatatype.A, use_edns=0, pad=128)
Expand All @@ -194,6 +202,7 @@ def test_padded_get(self):
"Aioquic cannot be imported; no DNS over HTTP3 (DOH3)",
)
class DNSOverHTTP3TestCase(unittest.TestCase):
@tests.util.retry_on_timeout
def testDoH3GetRequest(self):
nameserver_url = random.choice(KNOWN_ANYCAST_DOH3_RESOLVER_URLS)
q = dns.message.make_query("dns.google.", dns.rdatatype.A)
Expand All @@ -207,6 +216,7 @@ def testDoH3GetRequest(self):
)
self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def testDoH3PostRequest(self):
nameserver_url = random.choice(KNOWN_ANYCAST_DOH3_RESOLVER_URLS)
q = dns.message.make_query("dns.google.", dns.rdatatype.A)
Expand All @@ -220,6 +230,7 @@ def testDoH3PostRequest(self):
)
self.assertTrue(q.is_response(r))

@tests.util.retry_on_timeout
def test_build_url_from_ip(self):
self.assertTrue(resolver_v4_addresses or resolver_v6_addresses)
if resolver_v4_addresses:
Expand Down
Loading

0 comments on commit 6c2c566

Please sign in to comment.