Commit f8e8c3cc authored by Jason Madden's avatar Jason Madden

Allow a few tests to fail for dnspython.

A few cases of gethostbyaddr don't match the exception.
parent e803fb6d
The c-ares and DNSPython resolvers now raise exceptions much more The c-ares and DNSPython resolvers now raise exceptions much more
consistently with the standard resolver. Types and errnos are more consistently with the standard resolver. Types and errnos are more
likely to match. likely to match. (Depending on the system and configuration, it may
not match exactly, at least with DNSPython. There are still some rare
cases where the system resolver can raise ``herror`` bun DNSPython
will raise ``gaierror`` or vice versa. There doesn't seem to be a
deterministic way to account for this.)
In addition, several other small discrepancies were addressed, In addition, several other small discrepancies were addressed,
including handling of localhost and broadcast host names. including handling of localhost and broadcast host names.
...@@ -477,7 +477,12 @@ class Resolver(AbstractResolver): ...@@ -477,7 +477,12 @@ class Resolver(AbstractResolver):
try: try:
return resolver._gethostbyaddr(ip_address_bytes) return resolver._gethostbyaddr(ip_address_bytes)
except gaierror as ex: except gaierror as ex:
if ex.errno == EAI_NONAME: if ex.args[0] == EAI_NONAME:
# Note: The system doesn't *always* raise herror;
# sometimes the original gaierror propagates through.
# It's impossible to say ahead of time or just based
# on the name which it should be. The herror seems to
# be by far the most common, though.
raise herror(1, "Unknown host") raise herror(1, "Unknown host")
raise raise
......
...@@ -392,8 +392,8 @@ class TestCase(greentest.TestCase): ...@@ -392,8 +392,8 @@ class TestCase(greentest.TestCase):
return (result[0], [], result[2]) return (result[0], [], result[2])
return result return result
def _compare_exceptions(self, real_result, gevent_result): def _compare_exceptions(self, real_result, gevent_result, func_name):
msg = ('system:', repr(real_result), 'gevent:', repr(gevent_result)) msg = (func_name, 'system:', repr(real_result), 'gevent:', repr(gevent_result))
self.assertIs(type(gevent_result), type(real_result), msg) self.assertIs(type(gevent_result), type(real_result), msg)
if isinstance(real_result, TypeError): if isinstance(real_result, TypeError):
return return
...@@ -402,14 +402,14 @@ class TestCase(greentest.TestCase): ...@@ -402,14 +402,14 @@ class TestCase(greentest.TestCase):
if hasattr(real_result, 'errno'): if hasattr(real_result, 'errno'):
self.assertEqual(real_result.errno, gevent_result.errno) self.assertEqual(real_result.errno, gevent_result.errno)
def assertEqualResults(self, real_result, gevent_result, func): def assertEqualResults(self, real_result, gevent_result, func_name):
errors = (socket.gaierror, socket.herror, TypeError) errors = (socket.gaierror, socket.herror, TypeError)
if isinstance(real_result, errors) and isinstance(gevent_result, errors): if isinstance(real_result, errors) and isinstance(gevent_result, errors):
self._compare_exceptions(real_result, gevent_result) self._compare_exceptions(real_result, gevent_result, func_name)
return return
real_result = self._normalize_result(real_result, func) real_result = self._normalize_result(real_result, func_name)
gevent_result = self._normalize_result(gevent_result, func) gevent_result = self._normalize_result(gevent_result, func_name)
real_result_repr = repr(real_result) real_result_repr = repr(real_result)
gevent_result_repr = repr(gevent_result) gevent_result_repr = repr(gevent_result)
...@@ -418,8 +418,8 @@ class TestCase(greentest.TestCase): ...@@ -418,8 +418,8 @@ class TestCase(greentest.TestCase):
if relaxed_is_equal(gevent_result, real_result): if relaxed_is_equal(gevent_result, real_result):
return return
# If we're using the ares resolver, allow the real resolver to generate an # If we're using a different resolver, allow the real resolver to generate an
# error that the ares resolver actually gets an answer to. # error that the gevent resolver actually gets an answer to.
if ( if (
RESOLVER_NOT_SYSTEM RESOLVER_NOT_SYSTEM
...@@ -512,9 +512,27 @@ add( ...@@ -512,9 +512,27 @@ add(
skip_reason="Can return gaierror(-2)" skip_reason="Can return gaierror(-2)"
) )
def dnspython_lenient_compare_exceptions(self, real_result, gevent_result, func_name):
try:
TestCase._compare_exceptions(self, real_result, gevent_result, func_name)
except AssertionError:
# Allow gethostbyaddr to raise different things in a few rare cases.
if (
func_name != 'gethostbyaddr'
or type(real_result) not in (socket.herror, socket.gaierror)
or type(gevent_result) not in (socket.herror, socket.gaierror)
):
raise
util.log('WARNING: error type mismatch for %s: %r (gevent) != %r (stdlib)',
func_name,
gevent_result, real_result,
color='warning')
class TestNonexistent(TestCase): class TestNonexistent(TestCase):
pass if RESOLVER_DNSPYTHON:
_compare_exceptions = dnspython_lenient_compare_exceptions
add(TestNonexistent, 'nonexistentxxxyyy') add(TestNonexistent, 'nonexistentxxxyyy')
...@@ -803,13 +821,17 @@ class TestInterrupted_gethostbyname(gevent.testing.timing.AbstractGenericWaitTes ...@@ -803,13 +821,17 @@ class TestInterrupted_gethostbyname(gevent.testing.timing.AbstractGenericWaitTes
class TestBadName(TestCase): class TestBadName(TestCase):
pass if RESOLVER_DNSPYTHON:
_compare_exceptions = dnspython_lenient_compare_exceptions
add(TestBadName, 'xxxxxxxxxxxx')
add(TestBadName, 'xxxxxxxxxxxx')
class TestBadIP(TestCase): class TestBadIP(TestCase):
pass
if RESOLVER_DNSPYTHON:
_compare_exceptions = dnspython_lenient_compare_exceptions
add(TestBadIP, '1.2.3.400') add(TestBadIP, '1.2.3.400')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment