Skip to content

Commit

Permalink
Merge pull request #3208 from bdarnell/pin-tox
Browse files Browse the repository at this point in the history
ci: Various dependency-related updates
  • Loading branch information
bdarnell committed Dec 17, 2022
2 parents 274061a + 921d7a4 commit 9e9043e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 14 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# Lint python version must be synced with tox.ini
python-version: '3.8'
- name: Install tox
run: python -m pip install tox
run: python -m pip install tox -c maint/requirements.txt

- name: Run test suite
run: python -m tox -e py38,lint
Expand All @@ -44,8 +44,10 @@ jobs:
tox_env: py310-full
- python: '3.11'
tox_env: py311-full
- python: '3.12.0-alpha - 3.12'
tox_env: py312-full
# Need more work for python 3.12. See
# https://github.com/python/cpython/issues/93453
#- python: '3.12.0-alpha - 3.12'
# tox_env: py312-full
- python: 'pypy-3.8'
# Pypy is a lot slower due to jit warmup costs, so don't run the
# "full" test config there.
Expand All @@ -63,7 +65,7 @@ jobs:
- name: Install apt packages
run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev
- name: Install tox
run: python -m pip install tox
run: python -m pip install tox -c maint/requirements.txt

- name: Run test suite
run: python -m tox -e ${{ matrix.tox_env }}
Expand Down
13 changes: 7 additions & 6 deletions tornado/platform/caresresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
class CaresResolver(Resolver):
"""Name resolver based on the c-ares library.
This is a non-blocking and non-threaded resolver. It may not produce
the same results as the system resolver, but can be used for non-blocking
This is a non-blocking and non-threaded resolver. It may not produce the
same results as the system resolver, but can be used for non-blocking
resolution when threads cannot be used.
c-ares fails to resolve some names when ``family`` is ``AF_UNSPEC``,
so it is only recommended for use in ``AF_INET`` (i.e. IPv4). This is
the default for ``tornado.simple_httpclient``, but other libraries
may default to ``AF_UNSPEC``.
``pycares`` will not return a mix of ``AF_INET`` and ``AF_INET6`` when
``family`` is ``AF_UNSPEC``, so it is only recommended for use in
``AF_INET`` (i.e. IPv4). This is the default for
``tornado.simple_httpclient``, but other libraries may default to
``AF_UNSPEC``.
.. versionchanged:: 5.0
The ``io_loop`` argument (deprecated since version 4.1) has been removed.
Expand Down
8 changes: 7 additions & 1 deletion tornado/test/asyncio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ def setUp(self):
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())

def tearDown(self):
asyncio.get_event_loop_policy().get_event_loop().close()
try:
loop = asyncio.get_event_loop_policy().get_event_loop()
except Exception:
# We may not have a current event loop at this point.
pass
else:
loop.close()
asyncio.set_event_loop_policy(self.orig_policy)

def test_ioloop_close_leak(self):
Expand Down
9 changes: 8 additions & 1 deletion tornado/test/netutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ class _ResolverTestMixin(object):
@gen_test
def test_localhost(self: typing.Any):
addrinfo = yield self.resolver.resolve("localhost", 80, socket.AF_UNSPEC)
self.assertIn((socket.AF_INET, ("127.0.0.1", 80)), addrinfo)
# Most of the time localhost resovles to either the ipv4 loopback
# address alone, or ipv4+ipv6. But some versions of pycares will only
# return the ipv6 version, so we have to check for either one alone.
self.assertTrue(
((socket.AF_INET, ("127.0.0.1", 80)) in addrinfo)
or ((socket.AF_INET6, ("::1", 80)) in addrinfo),
f"loopback address not found in {addrinfo}",
)


# It is impossible to quickly and consistently generate an error in name
Expand Down
6 changes: 5 additions & 1 deletion tornado/test/tcpclient_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ def skipIfLocalhostV4(self):
def do_test_connect(self, family, host, source_ip=None, source_port=None):
port = self.start_server(family)
stream = yield self.client.connect(
host, port, source_ip=source_ip, source_port=source_port
host,
port,
source_ip=source_ip,
source_port=source_port,
af=family,
)
assert self.server is not None
server_stream = yield self.server.queue.get()
Expand Down
2 changes: 1 addition & 1 deletion tornado/test/testing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_fetch_segment(self):
def test_fetch_full_http_url(self):
# Ensure that self.fetch() recognizes absolute urls and does
# not transform them into references to our main test server.
path = "http://localhost:%d/path" % self.second_port
path = "http://127.0.0.1:%d/path" % self.second_port

response = self.fetch(path)
self.assertEqual(response.request.url, path)
Expand Down
11 changes: 11 additions & 0 deletions tornado/test/websocket_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import functools
import socket
import traceback
import typing
import unittest
Expand All @@ -9,6 +10,7 @@
from tornado.httpclient import HTTPError, HTTPRequest
from tornado.locks import Event
from tornado.log import gen_log, app_log
from tornado.netutil import Resolver
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.template import DictLoader
from tornado.testing import AsyncHTTPTestCase, gen_test, bind_unused_port, ExpectLog
Expand Down Expand Up @@ -539,6 +541,15 @@ def test_check_origin_invalid(self):
def test_check_origin_invalid_subdomains(self):
port = self.get_http_port()

# CaresResolver may return ipv6-only results for localhost, but our
# server is only running on ipv4. Test for this edge case and skip
# the test if it happens.
addrinfo = yield Resolver().resolve("localhost", port)
families = set(addr[0] for addr in addrinfo)
if socket.AF_INET not in families:
self.skipTest("localhost does not resolve to ipv4")
return

url = "ws://localhost:%d/echo" % port
# Subdomains should be disallowed by default. If we could pass a
# resolver to websocket_connect we could test sibling domains as well.
Expand Down

0 comments on commit 9e9043e

Please sign in to comment.