Commit fd0fcfe3 authored by Denis Bilenko's avatar Denis Bilenko

add test_ares_timeout.py

parent f27e9df1
import sys
import gevent
from gevent.resolver_ares import Resolver
from gevent import socket
print gevent.__file__
address = ('127.0.0.10', 53)
listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
listener.bind(address)
except socket.error, ex:
if 'permission denied' in str(ex).lower():
sys.stderr.write('This test binds on port 53 and thus must be run as root.\n')
sys.exit(0)
raise
def reader():
while True:
print listener.recvfrom(10000)
gevent.spawn(reader)
r = gevent.get_hub().resolver = Resolver(servers=['127.0.0.10'], timeout=0.001, tries=1)
try:
result = r.gethostbyname('www.google.com')
except socket.gaierror, ex:
if 'ARES_ETIMEOUT' not in str(ex):
raise
else:
raise AssertionError('Expected timeout, got %r' % (result, ))
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