Commit 92fc2c5d authored by Jason Madden's avatar Jason Madden

Refactor test_ares_timeout to a proper test.

parent 5d106191
......@@ -3,7 +3,13 @@
.. deprecated:: 1.3
Use :mod:`gevent.resolver.ares`
"""
import warnings
warnings.warn(
"gevent.resolver_ares is deprecated and will be removed in 1.5. "
"Use gevent.resolver.ares instead.",
DeprecationWarning
)
del warnings
from gevent.resolver.ares import * # pylint:disable=wildcard-import,unused-wildcard-import
import gevent.resolver.ares as _ares
__all__ = _ares.__all__
......
"""Backwards compatibility alias for :mod:`gevent.resolver.thread`.
.. deprecated:: 1.3
Use :mod:`gevent.resolver.cares`
Use :mod:`gevent.resolver.thread`
"""
import warnings
warnings.warn(
"gevent.resolver_thread is deprecated and will be removed in 1.5. "
"Use gevent.resolver.thread instead.",
DeprecationWarning
)
del warnings
from gevent.resolver.thread import * # pylint:disable=wildcard-import,unused-wildcard-import
import gevent.resolver.thread as _thread
__all__ = _thread.__all__
......
from __future__ import print_function
import sys
import errno
import unittest
import gevent
try:
from gevent.resolver_ares import Resolver
from gevent.resolver.ares import Resolver
except ImportError as ex:
print(ex)
sys.exit(0)
Resolver = None
from gevent import socket
print(gevent.__file__)
address = ('', 7153)
listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
import gevent.testing as greentest
try:
listener.bind(address)
except socket.error as ex:
if ex.errno in (errno.EPERM, errno.EADDRNOTAVAIL) or 'permission denied' in str(ex).lower():
sys.stderr.write('This test binds on port a port that was already in use or not allowed.\n')
sys.exit(0)
raise
@unittest.skipIf(
Resolver is None,
"Needs ares resolver"
)
class TestTimeout(greentest.TestCase):
__timeout__ = 30
def reader():
while True:
print(listener.recvfrom(10000))
address = ('', 7153)
gevent.spawn(reader)
def test(self):
listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
r = gevent.get_hub().resolver = Resolver(servers=['127.0.0.1'], timeout=0.001, tries=1, udp_port=address[-1])
try:
result = r.gethostbyname('www.google.com')
except socket.gaierror as ex:
if 'ARES_ETIMEOUT' not in str(ex):
raise
else:
raise AssertionError('Expected timeout, got %r' % (result, ))
try:
listener.bind(self.address)
except socket.error as ex:
if ex.errno in (errno.EPERM, errno.EADDRNOTAVAIL) or 'permission denied' in str(ex).lower():
raise unittest.SkipTest(
'This test binds on port a port that was already in use or not allowed.\n'
)
raise
def reader():
while True:
listener.recvfrom(10000)
gevent.spawn(reader)
r = Resolver(servers=['127.0.0.1'], timeout=0.001, tries=1,
udp_port=self.address[-1])
with self.assertRaisesRegex(socket.gaierror, "ARES_ETIMEOUT"):
r.gethostbyname('www.google.com')
if __name__ == '__main__':
greentest.main()
......@@ -2,3 +2,4 @@ test___monkey_patching.py
test__monkey_ssl_warning.py
test___monitor.py
test__monkey_scope.py
test_ares_timeout.py
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