[3.11] gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016) by vstinner · Pull Request #109042 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion Lib/test/support/socket_helper.py
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ def test_create_connection_local_addr(self):
self.assertEqual(port, expected)
tr.close()

@socket_helper.skip_if_tcp_blackhole
def test_create_connection_local_addr_skip_different_family(self):
# See https://github.com/python/cpython/issues/86508
port1 = socket_helper.find_unused_port()
Expand All @@ -692,6 +693,7 @@ async def getaddrinfo(host, port, *args, **kwargs):
with self.assertRaises(OSError):
self.loop.run_until_complete(f)

@socket_helper.skip_if_tcp_blackhole
def test_create_connection_local_addr_nomatch_family(self):
# See https://github.com/python/cpython/issues/86508
port1 = socket_helper.find_unused_port()
Expand Down Expand Up @@ -1248,6 +1250,7 @@ def connection_made(self, transport):

server.close()

@socket_helper.skip_if_tcp_blackhole
def test_server_close(self):
f = self.loop.create_server(MyProto, '0.0.0.0', 0)
server = self.loop.run_until_complete(f)
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_asyncio/test_sock_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from test import support
from test.support import socket_helper

if socket_helper.tcp_blackhole():
raise unittest.SkipTest('Not relevant to ProactorEventLoop')


def tearDownModule():
asyncio.set_event_loop_policy(None)

Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import weakref
from test import support
from test.support import socket_helper
from unittest import mock
try:
import ssl
Expand Down Expand Up @@ -350,6 +351,7 @@ async def client(addr):
support.gc_collect()
self.assertIsNone(client_context())

@socket_helper.skip_if_tcp_blackhole
def test_start_tls_client_buf_proto_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE

Expand Down Expand Up @@ -502,6 +504,7 @@ async def client(addr):
asyncio.wait_for(client(srv.addr),
timeout=support.SHORT_TIMEOUT))

@socket_helper.skip_if_tcp_blackhole
def test_start_tls_server_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
ANSWER = b'answer'
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_that_Time2Internaldate_returns_a_result(self):
for t in self.timevalues():
imaplib.Time2Internaldate(t)

@socket_helper.skip_if_tcp_blackhole
def test_imap4_host_default_value(self):
# Check whether the IMAP4_PORT is truly unavailable.
with socket.socket() as s:
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5171,6 +5171,7 @@ def mocked_socket_module(self):
finally:
socket.socket = old_socket

@socket_helper.skip_if_tcp_blackhole
def test_connect(self):
port = socket_helper.find_unused_port()
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand All @@ -5179,6 +5180,7 @@ def test_connect(self):
cli.connect((HOST, port))
self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)

@socket_helper.skip_if_tcp_blackhole
def test_create_connection(self):
# Issue #9792: errors raised by create_connection() should have
# a proper errno attribute.
Expand Down