8000 gh-126483: disable warnings filters mutation in concurrent test (GH-1… · miss-islington/cpython@1421ad3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1421ad3

Browse files
graingertmiss-islington
authored andcommitted
pythongh-126483: disable warnings filters mutation in concurrent test (pythonGH-132694)
The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Only check for warnings when the context aware warnings feature is enabled, which makes the warnings filter context-local and thread-safe. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com>
1 parent d446dbc commit 1421ad3

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Lib/test/test_ssl.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import platform
3232
import sysconfig
3333
import functools
34+
from contextlib import nullcontext
3435
try:
3536
import ctypes
3637
except ImportError:
@@ -2871,6 +2872,7 @@ def test_ssl_in_multiple_threads(self):
28712872
# See GH-124984: OpenSSL is not thread safe.
28722873
threads = []
28732874

2875+
warnings_filters = sys.flags.context_aware_warnings
28742876
global USE_SAME_TEST_CONTEXT
28752877
USE_SAME_TEST_CONTEXT = True
28762878
try:
@@ -2879,7 +2881,10 @@ def test_ssl_in_multiple_threads(self):
28792881
self.test_alpn_protocols,
28802882
self.test_getpeercert,
28812883
self.test_crl_check,
2882-
self.test_check_hostname_idn,
2884+
functools.partial(
2885+
self.test_check_hostname_idn,
2886+
warnings_filters=warnings_filters,
2887+
),
28832888
self.test_wrong_cert_tls12,
28842889
self.test_wrong_cert_tls13,
28852890
):
@@ -3125,7 +3130,7 @@ def test_dual_rsa_ecc(self):
31253130
cipher = s.cipher()[0].split('-')
31263131
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
31273132

3128-
def test_check_hostname_idn(self):
3133+
def test_check_hostname_idn(self, warnings_filters=True):
31293134
if support.verbose:
31303135
sys.stdout.write("\n")
31313136

@@ -3180,16 +3185,30 @@ def test_check_hostname_idn(self):
31803185
server_hostname="python.example.org") as s:
31813186
with self.assertRaises(ssl.CertificateError):
31823187
s.connect((HOST, server.port))
3183-
with ThreadedEchoServer(context=server_context, chatty=True) as server:
3184-
with warnings_helper.check_no_resource_warning(self):
3185-
with self.assertRaises(UnicodeError):
3186-
context.wrap_socket(socket.socket(),
3187-
server_hostname='.pythontest.net')
3188-
with ThreadedEchoServer(context=server_context, chatty=True) as server:
3189-
with warnings_helper.check_no_resource_warning(self):
3190-
with self.assertRaises(UnicodeDecodeError):
3191-
context.wrap_socket(socket.socket(),
3192-
server_hostname=b'k\xf6nig.idn.pythontest.net')
3188+
with (
3189+
ThreadedEchoServer(context=server_context, chatty=True) as server,
3190+
(
3191+
warnings_helper.check_no_resource_warning(self)
3192+
if warnings_filters
3193+
else nullcontext()
3194+
),
3195+
self.assertRaises(UnicodeError),
3196+
):
3197+
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')
3198+
3199+
with (
3200+
ThreadedEchoServer(context=server_context, chatty=True) as server,
3201+
(
3202+
warnings_helper.check_no_resource_warning(self)
3203+
if warnings_filters
3204+
else nullcontext()
3205+
),
3206+
self.assertRaises(UnicodeDecodeError),
3207+
):
3208+
context.wrap_socket(
3209+
socket.socket(),
3210+
server_hostname=b'k\xf6nig.idn.pythontest.net',
3211+
)
31933212

31943213
def test_wrong_cert_tls12(self):
31953214
"""Connecting when the server rejects the client's certificate

0 commit comments

Comments
 (0)
0