Files
deb-python-eventlet/tests/socket_test.py
Jakub Stasiak 861d684399 socket: Actually provide non-blocking DNS methods
The green socket module seemed to have only blocking DNS resolution
methods even with dnspython installed which is inconsistent with the
documentation.

This patch has a few consequences:

* an import cycle is eliminated
* if an import cycle reappears here it'll be visible

Note: eliminating the import cycle revealed an issue related to monkey
patching and the way we perform greendns tests (the test failures were
already present on Python 3.5[1] as that version has some import cycle
handling changes). The failures look like this:

======================================================================
FAIL: test_query_ans_types (tests.greendns_test.TestHostsResolver)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kuba/projects/eventlet/tests/greendns_test.py", line 97, in test_query_ans_types
    assert isinstance(ans, greendns.dns.resolver.Answer)
AssertionError

======================================================================
FAIL: test_query_unknown_no_raise (tests.greendns_test.TestHostsResolver)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kuba/projects/eventlet/tests/greendns_test.py", line 129, in test_query_unknown_no_raise
    assert isinstance(ans, greendns.dns.resolver.Answer)
AssertionError

This issue will be addressed in a separate commit.

This patch is contributed by Smarkets Limited.

[1] https://github.com/eventlet/eventlet/issues/267
2016-05-18 14:24:10 +02:00

46 lines
1.3 KiB
Python

import eventlet
from eventlet.green import socket
try:
from eventlet.support import greendns
has_greendns = True
except ImportError:
has_greendns = False
from tests import skip_if
def test_create_connection_error():
try:
socket.create_connection(('192.0.2.1', 80), timeout=0.1)
except (IOError, OSError):
pass
def test_recv_type():
# https://github.com/eventlet/eventlet/issues/245
# socket recv returning multiple data types
# For this test to work, client and server have to be in separate
# processes or OS threads. Just running two greenthreads gives
# false test pass.
threading = eventlet.patcher.original('threading')
addr = []
def server():
sock = eventlet.listen(('127.0.0.1', 0))
addr[:] = sock.getsockname()
eventlet.sleep(0.2)
server_thread = threading.Thread(target=server)
server_thread.start()
eventlet.sleep(0.1)
sock = eventlet.connect(tuple(addr))
s = sock.recv(1)
assert isinstance(s, bytes)
@skip_if(not has_greendns)
def test_dns_methods_are_green():
assert socket.gethostbyname is greendns.gethostbyname
assert socket.gethostbyname_ex is greendns.gethostbyname_ex
assert socket.getaddrinfo is greendns.getaddrinfo
assert socket.getnameinfo is greendns.getnameinfo