From 27b01f94014b26778fcdd5d379b1810f4ceb4be2 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 12:52:44 +0200 Subject: [PATCH 01/14] Make reusable *NIX check marker in connector tests --- tests/test_connector.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index 3bf01b08fe4..3e5a8351b48 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -24,6 +24,12 @@ from aiohttp.tracing import Trace +IS_UNIX = hasattr(socket, 'AF_UNIX') +"""Specifies whether the current runtime is *NIX.""" + +needs_unix = pytest.mark.skipif(not IS_UNIX, reason='requires UNIX sockets') + + @pytest.fixture() def key(): """Connection key""" @@ -43,6 +49,7 @@ def ssl_key(): @pytest.fixture +@needs_unix def unix_sockname(tmp_path): return str(tmp_path / 'socket.sock') @@ -1956,8 +1963,7 @@ async def handler(request): assert r.status == 200 -@pytest.mark.skipif(not hasattr(socket, 'AF_UNIX'), - reason="requires unix socket") +@needs_unix async def test_unix_connector_not_found(loop) -> None: connector = aiohttp.UnixConnector('/' + uuid.uuid4().hex, loop=loop) @@ -1968,8 +1974,7 @@ async def test_unix_connector_not_found(loop) -> None: await connector.connect(req, None, ClientTimeout()) -@pytest.mark.skipif(not hasattr(socket, 'AF_UNIX'), - reason="requires unix socket") +@needs_unix async def test_unix_connector_permission(loop) -> None: loop.create_unix_connection = make_mocked_coro( raise_exception=PermissionError()) @@ -2094,8 +2099,6 @@ async def handler(request): conn.close() -@pytest.mark.skipif(not hasattr(socket, 'AF_UNIX'), - reason='requires UNIX sockets') async def test_unix_connector(unix_server, unix_sockname) -> None: async def handler(request): return web.Response() From 5e6b2dd820361a5900d87a0b3b0b1cd2b593fa2f Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 13:01:58 +0200 Subject: [PATCH 02/14] Add an exit-check @ unix_sockname fixture --- tests/test_connector.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index 3e5a8351b48..2194bdd4fd1 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -24,6 +24,10 @@ from aiohttp.tracing import Trace +IS_HPUX = sys.platform.startswith('hp-ux') +"""Specifies whether the current runtime is HP-UX.""" +IS_LINUX = sys.platform.startswith('linux') +"""Specifies whether the current runtime is HP-UX.""" IS_UNIX = hasattr(socket, 'AF_UNIX') """Specifies whether the current runtime is *NIX.""" @@ -51,7 +55,35 @@ def ssl_key(): @pytest.fixture @needs_unix def unix_sockname(tmp_path): - return str(tmp_path / 'socket.sock') + """Generate an fs path to the UNIX domain socket for testing. + + N.B. Different OS kernels have different fs path length limitations + for it. For Linux, it's 108, for HP-UX it's 92 (or higher) depending + on its version. For for most of the BSDs (Open, Free, macOS) it's + mostly 104 but sometimes it can be down to 100. + + Ref: https://github.com/aio-libs/aiohttp/issues/3572 + """ + max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100 + """Amount of bytes allocated for the UNIX socket path by OS kernel. + + Ref: https://unix.stackexchange.com/a/367012/27133 + """ + + sock_path = str(tmp_path / 'socket.sock') + sock_path_len = len(sock_path.encode()) + + # exit-check to verify that it's correct and simplify debugging + # in the future + assert sock_path_len <= max_sock_len, ( + f'Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes ' + f'long but the current kernel only has {max_sock_len} bytes ' + 'allocated to hold it so it must be shorter. ' + 'See https://github.com/aio-libs/aiohttp/issues/3572 ' + 'for more info.' + ) + + return sock_path @pytest.fixture From aee9bf40e2f70a59bea7ce5b4710cac130826824 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 15:13:42 +0200 Subject: [PATCH 03/14] Fix isort linter complaint --- tests/test_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index 2194bdd4fd1..ea1faba6a74 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -23,7 +23,6 @@ from aiohttp.test_utils import make_mocked_coro, unused_port from aiohttp.tracing import Trace - IS_HPUX = sys.platform.startswith('hp-ux') """Specifies whether the current runtime is HP-UX.""" IS_LINUX = sys.platform.startswith('linux') From c3dac51de65944c9da25621f4f9ff500480d6998 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 15:17:48 +0200 Subject: [PATCH 04/14] Generate a shorter path for test UNIX sockets --- tests/test_connector.py | 72 ++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index ea1faba6a74..e39d40f1178 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -3,12 +3,16 @@ import asyncio import gc import hashlib +import os import platform import socket import ssl import sys import uuid from collections import deque +from hashlib import md5 +from pathlib import Path +from tempfile import TemporaryDirectory from unittest import mock import pytest @@ -53,7 +57,7 @@ def ssl_key(): @pytest.fixture @needs_unix -def unix_sockname(tmp_path): +def unix_sockname(tmp_path, tmp_path_factory): """Generate an fs path to the UNIX domain socket for testing. N.B. Different OS kernels have different fs path length limitations @@ -69,20 +73,64 @@ def unix_sockname(tmp_path): Ref: https://unix.stackexchange.com/a/367012/27133 """ - sock_path = str(tmp_path / 'socket.sock') + sock_file_name = 'unix.sock' + + root_tmp_dir = Path('/tmp').resolve() + os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() + original_base_tmp_path = Path(tmp_path_factory.getbasetemp()) + + original_base_tmp_path_hash = md5( + str(original_base_tmp_path).encode(), + ).hexdigest() + + def make_tmp_dir(base_tmp_dir): + return TemporaryDirectory( + dir=base_tmp_dir, + prefix='pt-', + suffix='-{}'.format(original_base_tmp_path_hash), + ) + + def assert_sock_fits(sock_path): + sock_path_len = len(sock_path.encode()) + # exit-check to verify that it's correct and simplify debugging + # in the future + assert sock_path_len <= max_sock_len, ( + 'Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes ' + 'long but the current kernel only has {max_sock_len} bytes ' + 'allocated to hold it so it must be shorter. ' + 'See https://github.com/aio-libs/aiohttp/issues/3572 ' + 'for more info.' + ).format_map(locals()) + + sock_path = str(tmp_path.resolve() / sock_file_name) sock_path_len = len(sock_path.encode()) - # exit-check to verify that it's correct and simplify debugging - # in the future - assert sock_path_len <= max_sock_len, ( - f'Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes ' - f'long but the current kernel only has {max_sock_len} bytes ' - 'allocated to hold it so it must be shorter. ' - 'See https://github.com/aio-libs/aiohttp/issues/3572 ' - 'for more info.' - ) + if original_base_tmp_path == root_tmp_dir and os_tmp_dir == root_tmp_dir: + assert_sock_fits(sock_path) + + if sock_path_len <= max_sock_len: + yield sock_path + return + + with make_tmp_dir(os_tmp_dir) as tmpd: + sock_path = str(tmpd.resolve() / sock_file_name) + sock_path_len = len(sock_path.encode()) + + if os_tmp_dir == root_tmp_dir: + assert_sock_fits(sock_path) + # exit-check to verify that it's correct and simplify debugging + # in the future + if sock_path_len <= max_sock_len: + yield sock_path + return + + with make_tmp_dir(root_tmp_dir) as tmpd: + sock_path = str(tmpd.resolve() / sock_file_name) + + assert_sock_fits(sock_path) - return sock_path + yield sock_path + return @pytest.fixture From 32b8957ba323ad65106ce328d01e987d8802e451 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 15:32:39 +0200 Subject: [PATCH 05/14] Migrate unix_sockname fixture to conftest module --- tests/conftest.py | 96 +++++++++++++++++++++++++++++++++++++++- tests/test_connector.py | 86 ----------------------------------- tests/test_web_runner.py | 7 ++- 3 files changed, 97 insertions(+), 92 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c8b3749e1ce..0a296f1ab29 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,11 +1,25 @@ -import hashlib +import os +import socket import ssl +import sys +from hashlib import md5, sha256 +from pathlib import Path +from tempfile import TemporaryDirectory import pytest import trustme pytest_plugins = ['aiohttp.pytest_plugin', 'pytester'] +IS_HPUX = sys.platform.startswith('hp-ux') +"""Specifies whether the current runtime is HP-UX.""" +IS_LINUX = sys.platform.startswith('linux') +"""Specifies whether the current runtime is HP-UX.""" +IS_UNIX = hasattr(socket, 'AF_UNIX') +"""Specifies whether the current runtime is *NIX.""" + +needs_unix = pytest.mark.skipif(not IS_UNIX, reason='requires UNIX sockets') + @pytest.fixture def tls_certificate_authority(): @@ -55,4 +69,82 @@ def tls_certificate_pem_bytes(tls_certificate): @pytest.fixture def tls_certificate_fingerprint_sha256(tls_certificate_pem_bytes): tls_cert_der = ssl.PEM_cert_to_DER_cert(tls_certificate_pem_bytes.decode()) - return hashlib.sha256(tls_cert_der).digest() + return sha256(tls_cert_der).digest() + + +@pytest.fixture +@needs_unix +def unix_sockname(tmp_path, tmp_path_factory): + """Generate an fs path to the UNIX domain socket for testing. + + N.B. Different OS kernels have different fs path length limitations + for it. For Linux, it's 108, for HP-UX it's 92 (or higher) depending + on its version. For for most of the BSDs (Open, Free, macOS) it's + mostly 104 but sometimes it can be down to 100. + + Ref: https://github.com/aio-libs/aiohttp/issues/3572 + """ + max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100 + """Amount of bytes allocated for the UNIX socket path by OS kernel. + + Ref: https://unix.stackexchange.com/a/367012/27133 + """ + + sock_file_name = 'unix.sock' + + root_tmp_dir = Path('/tmp').resolve() + os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() + original_base_tmp_path = Path(tmp_path_factory.getbasetemp()) + + original_base_tmp_path_hash = md5( + str(original_base_tmp_path).encode(), + ).hexdigest() + + def make_tmp_dir(base_tmp_dir): + return TemporaryDirectory( + dir=base_tmp_dir, + prefix='pt-', + suffix='-{}'.format(original_base_tmp_path_hash), + ) + + def assert_sock_fits(sock_path): + sock_path_len = len(sock_path.encode()) + # exit-check to verify that it's correct and simplify debugging + # in the future + assert sock_path_len <= max_sock_len, ( + 'Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes ' + 'long but the current kernel only has {max_sock_len} bytes ' + 'allocated to hold it so it must be shorter. ' + 'See https://github.com/aio-libs/aiohttp/issues/3572 ' + 'for more info.' + ).format_map(locals()) + + sock_path = str(tmp_path.resolve() / sock_file_name) + sock_path_len = len(sock_path.encode()) + + if original_base_tmp_path == root_tmp_dir and os_tmp_dir == root_tmp_dir: + assert_sock_fits(sock_path) + + if sock_path_len <= max_sock_len: + yield sock_path + return + + with make_tmp_dir(os_tmp_dir) as tmpd: + sock_path = str(tmpd.resolve() / sock_file_name) + sock_path_len = len(sock_path.encode()) + + if os_tmp_dir == root_tmp_dir: + assert_sock_fits(sock_path) + # exit-check to verify that it's correct and simplify debugging + # in the future + if sock_path_len <= max_sock_len: + yield sock_path + return + + with make_tmp_dir(root_tmp_dir) as tmpd: + sock_path = str(tmpd.resolve() / sock_file_name) + + assert_sock_fits(sock_path) + + yield sock_path + return diff --git a/tests/test_connector.py b/tests/test_connector.py index e39d40f1178..20adf274da5 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -3,16 +3,12 @@ import asyncio import gc import hashlib -import os import platform import socket import ssl import sys import uuid from collections import deque -from hashlib import md5 -from pathlib import Path -from tempfile import TemporaryDirectory from unittest import mock import pytest @@ -27,10 +23,6 @@ from aiohttp.test_utils import make_mocked_coro, unused_port from aiohttp.tracing import Trace -IS_HPUX = sys.platform.startswith('hp-ux') -"""Specifies whether the current runtime is HP-UX.""" -IS_LINUX = sys.platform.startswith('linux') -"""Specifies whether the current runtime is HP-UX.""" IS_UNIX = hasattr(socket, 'AF_UNIX') """Specifies whether the current runtime is *NIX.""" @@ -55,84 +47,6 @@ def ssl_key(): return ConnectionKey('localhost', 80, True, None, None, None, None) -@pytest.fixture -@needs_unix -def unix_sockname(tmp_path, tmp_path_factory): - """Generate an fs path to the UNIX domain socket for testing. - - N.B. Different OS kernels have different fs path length limitations - for it. For Linux, it's 108, for HP-UX it's 92 (or higher) depending - on its version. For for most of the BSDs (Open, Free, macOS) it's - mostly 104 but sometimes it can be down to 100. - - Ref: https://github.com/aio-libs/aiohttp/issues/3572 - """ - max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100 - """Amount of bytes allocated for the UNIX socket path by OS kernel. - - Ref: https://unix.stackexchange.com/a/367012/27133 - """ - - sock_file_name = 'unix.sock' - - root_tmp_dir = Path('/tmp').resolve() - os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() - original_base_tmp_path = Path(tmp_path_factory.getbasetemp()) - - original_base_tmp_path_hash = md5( - str(original_base_tmp_path).encode(), - ).hexdigest() - - def make_tmp_dir(base_tmp_dir): - return TemporaryDirectory( - dir=base_tmp_dir, - prefix='pt-', - suffix='-{}'.format(original_base_tmp_path_hash), - ) - - def assert_sock_fits(sock_path): - sock_path_len = len(sock_path.encode()) - # exit-check to verify that it's correct and simplify debugging - # in the future - assert sock_path_len <= max_sock_len, ( - 'Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes ' - 'long but the current kernel only has {max_sock_len} bytes ' - 'allocated to hold it so it must be shorter. ' - 'See https://github.com/aio-libs/aiohttp/issues/3572 ' - 'for more info.' - ).format_map(locals()) - - sock_path = str(tmp_path.resolve() / sock_file_name) - sock_path_len = len(sock_path.encode()) - - if original_base_tmp_path == root_tmp_dir and os_tmp_dir == root_tmp_dir: - assert_sock_fits(sock_path) - - if sock_path_len <= max_sock_len: - yield sock_path - return - - with make_tmp_dir(os_tmp_dir) as tmpd: - sock_path = str(tmpd.resolve() / sock_file_name) - sock_path_len = len(sock_path.encode()) - - if os_tmp_dir == root_tmp_dir: - assert_sock_fits(sock_path) - # exit-check to verify that it's correct and simplify debugging - # in the future - if sock_path_len <= max_sock_len: - yield sock_path - return - - with make_tmp_dir(root_tmp_dir) as tmpd: - sock_path = str(tmpd.resolve() / sock_file_name) - - assert_sock_fits(sock_path) - - yield sock_path - return - - @pytest.fixture def unix_server(loop, unix_sockname): runners = [] diff --git a/tests/test_web_runner.py b/tests/test_web_runner.py index 6a94ae1df82..dbaaf1b17ae 100644 --- a/tests/test_web_runner.py +++ b/tests/test_web_runner.py @@ -102,15 +102,14 @@ def test_non_app() -> None: @pytest.mark.skipif(platform.system() == "Windows", reason="Unix socket support is required") -async def test_addresses(make_runner, tmpdir) -> None: +async def test_addresses(make_runner, unix_sockname) -> None: _sock = get_unused_port_socket('127.0.0.1') runner = make_runner() await runner.setup() tcp = web.SockSite(runner, _sock) await tcp.start() - path = str(tmpdir / 'tmp.sock') - unix = web.UnixSite(runner, path) + unix = web.UnixSite(runner, unix_sockname) await unix.start() actual_addrs = runner.addresses expected_host, expected_post = _sock.getsockname()[:2] - assert actual_addrs == [(expected_host, expected_post), path] + assert actual_addrs == [(expected_host, expected_post), unix_sockname] From 1e415f4b72ebeac9f9bb148794022fd7e3bff182 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sun, 9 Jun 2019 17:47:17 +0200 Subject: [PATCH 06/14] Stringify the original base path --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0a296f1ab29..72420a851a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -94,7 +94,7 @@ def unix_sockname(tmp_path, tmp_path_factory): root_tmp_dir = Path('/tmp').resolve() os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() - original_base_tmp_path = Path(tmp_path_factory.getbasetemp()) + original_base_tmp_path = Path(str(tmp_path_factory.getbasetemp())) original_base_tmp_path_hash = md5( str(original_base_tmp_path).encode(), From 9e2c9f3239cc8be0ee6ca63242419d04025a3d8c Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 10 Jun 2019 16:05:42 +0200 Subject: [PATCH 07/14] Simplify unix_sockname fixture --- tests/conftest.py | 62 ++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 72420a851a5..ee1088b1896 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ from hashlib import md5, sha256 from pathlib import Path from tempfile import TemporaryDirectory +from uuid import uuid4 import pytest import trustme @@ -91,10 +92,14 @@ def unix_sockname(tmp_path, tmp_path_factory): """ sock_file_name = 'unix.sock' + unique_prefix = '{!s}-'.format(uuid4()) + unique_prefix_len = len(unique_prefix) root_tmp_dir = Path('/tmp').resolve() os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() - original_base_tmp_path = Path(str(tmp_path_factory.getbasetemp())) + original_base_tmp_path = Path( + str(tmp_path_factory.getbasetemp()), + ).resolve() original_base_tmp_path_hash = md5( str(original_base_tmp_path).encode(), @@ -119,32 +124,29 @@ def assert_sock_fits(sock_path): 'for more info.' ).format_map(locals()) - sock_path = str(tmp_path.resolve() / sock_file_name) - sock_path_len = len(sock_path.encode()) - - if original_base_tmp_path == root_tmp_dir and os_tmp_dir == root_tmp_dir: - assert_sock_fits(sock_path) - - if sock_path_len <= max_sock_len: - yield sock_path - return - - with make_tmp_dir(os_tmp_dir) as tmpd: - sock_path = str(tmpd.resolve() / sock_file_name) - sock_path_len = len(sock_path.encode()) - - if os_tmp_dir == root_tmp_dir: - assert_sock_fits(sock_path) - # exit-check to verify that it's correct and simplify debugging - # in the future - if sock_path_len <= max_sock_len: - yield sock_path - return - - with make_tmp_dir(root_tmp_dir) as tmpd: - sock_path = str(tmpd.resolve() / sock_file_name) - - assert_sock_fits(sock_path) - - yield sock_path - return + paths = original_base_tmp_path, os_tmp_dir, root_tmp_dir + unique_paths = [p for n, p in enumerate(paths) if p not in paths[:n]] + paths_num = len(unique_paths) + + for num, tmp_dir_path in enumerate(paths, 1): + with make_tmp_dir(tmp_dir_path) as tmpd: + tmpd = Path(tmpd).resolve() + sock_path = str(tmpd / sock_file_name) + sock_path_len = len(sock_path.encode()) + + if num >= paths_num: + # exit-check to verify that it's correct and simplify + # debugging in the future + assert_sock_fits(sock_path) + + if sock_path_len <= max_sock_len: + if max_sock_len - sock_path_len >= unique_prefix_len: + # If we're lucky to have extra space in the path, + # let's also make it more unique + sock_path = str( + tmpd / ''.join((unique_prefix, sock_file_name)) + ) + # Double-checking it: + assert_sock_fits(sock_path) + yield sock_path + return From ba612f36180f04f7a5c9d8a1ae985e882169c222 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 10 Jun 2019 16:08:05 +0200 Subject: [PATCH 08/14] Keep needs_unix fixture only in conftest --- tests/test_connector.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index 20adf274da5..dfdef78b629 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -23,10 +23,7 @@ from aiohttp.test_utils import make_mocked_coro, unused_port from aiohttp.tracing import Trace -IS_UNIX = hasattr(socket, 'AF_UNIX') -"""Specifies whether the current runtime is *NIX.""" - -needs_unix = pytest.mark.skipif(not IS_UNIX, reason='requires UNIX sockets') +from conftest import needs_unix @pytest.fixture() From 7304b49aab4ab28c2d56ef8e5af62dcd3f7eb56d Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 10 Jun 2019 16:14:57 +0200 Subject: [PATCH 09/14] Fix skipping in unix_sockname Skip marks don't work in fixtures --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index ee1088b1896..45554303a99 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -74,7 +74,6 @@ def tls_certificate_fingerprint_sha256(tls_certificate_pem_bytes): @pytest.fixture -@needs_unix def unix_sockname(tmp_path, tmp_path_factory): """Generate an fs path to the UNIX domain socket for testing. @@ -85,6 +84,9 @@ def unix_sockname(tmp_path, tmp_path_factory): Ref: https://github.com/aio-libs/aiohttp/issues/3572 """ + if not IS_UNIX: + pytest.skip(reason='requires UNIX sockets') + max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100 """Amount of bytes allocated for the UNIX socket path by OS kernel. From 5825337119a1544216aa76458d605baca1f33d6a Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 10 Jun 2019 16:18:34 +0200 Subject: [PATCH 10/14] Calculate prefix bytes len --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 45554303a99..5af26de7968 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -95,7 +95,7 @@ def unix_sockname(tmp_path, tmp_path_factory): sock_file_name = 'unix.sock' unique_prefix = '{!s}-'.format(uuid4()) - unique_prefix_len = len(unique_prefix) + unique_prefix_len = len(unique_prefix.encode()) root_tmp_dir = Path('/tmp').resolve() os_tmp_dir = Path(os.getenv('TMPDIR', '/tmp')).resolve() From a00447007d6cb1a586e45d060c835d3535dc7e28 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Mon, 10 Jun 2019 16:23:47 +0200 Subject: [PATCH 11/14] Drop unnecessary win check marker --- tests/test_web_runner.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_web_runner.py b/tests/test_web_runner.py index dbaaf1b17ae..233e9322a8d 100644 --- a/tests/test_web_runner.py +++ b/tests/test_web_runner.py @@ -100,8 +100,6 @@ def test_non_app() -> None: web.AppRunner(object()) -@pytest.mark.skipif(platform.system() == "Windows", - reason="Unix socket support is required") async def test_addresses(make_runner, unix_sockname) -> None: _sock = get_unused_port_socket('127.0.0.1') runner = make_runner() From ca1aa0289c8b8f8770473dfc876012a081a086e7 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 11 Jun 2019 11:32:54 +0200 Subject: [PATCH 12/14] Drop reason kwarg from pytest.skip() invocation --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5af26de7968..5babac7d08e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,7 +85,7 @@ def unix_sockname(tmp_path, tmp_path_factory): Ref: https://github.com/aio-libs/aiohttp/issues/3572 """ if not IS_UNIX: - pytest.skip(reason='requires UNIX sockets') + pytest.skip('requires UNIX sockets') max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100 """Amount of bytes allocated for the UNIX socket path by OS kernel. From de52806322264ba279a299731144ff85cf026a7d Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 11 Jun 2019 11:36:00 +0200 Subject: [PATCH 13/14] Satisfy isort --- tests/test_connector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index dfdef78b629..9be14d07004 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -22,7 +22,6 @@ from aiohttp.helpers import PY_37 from aiohttp.test_utils import make_mocked_coro, unused_port from aiohttp.tracing import Trace - from conftest import needs_unix From a74e524d217072290d648874a76a75b206582256 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 11 Jun 2019 13:24:30 +0200 Subject: [PATCH 14/14] Make make_tmp_dir Python-3.5-compatible --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5babac7d08e..d5079200b88 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -109,9 +109,9 @@ def unix_sockname(tmp_path, tmp_path_factory): def make_tmp_dir(base_tmp_dir): return TemporaryDirectory( - dir=base_tmp_dir, + dir=str(base_tmp_dir), prefix='pt-', - suffix='-{}'.format(original_base_tmp_path_hash), + suffix='-{!s}'.format(original_base_tmp_path_hash), ) def assert_sock_fits(sock_path):