Skip to content
Draft
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
70 changes: 33 additions & 37 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from test.support import warnings_helper
from test.support import asyncore
import array
import contextlib
import re
import socket
import select
Expand Down Expand Up @@ -2996,46 +2997,41 @@ def test_echo(self):
str(e.exception))

@unittest.skipUnless(support.Py_GIL_DISABLED, "test is only useful if the GIL is disabled")
def test_ssl_in_multiple_threads(self):
@support.bigmemtest(size=12 * 2**30, memuse=1, dry_run=False)
def test_ssl_in_multiple_threads(self, size):
# See GH-124984: OpenSSL is not thread safe.
self.enterContext(
support.swap_item(globals(), 'USE_SAME_TEST_CONTEXT', True))
self.enterContext(
support.swap_attr(self, 'subTest',
lambda *args, **kwargs: contextlib.nullcontext()))
warnings_filters = sys.flags.context_aware_warnings
funcs = (
self.test_echo,
self.test_alpn_protocols,
self.test_getpeercert,
self.test_crl_check,
functools.partial(
self.test_check_hostname_idn,
warnings_filters=warnings_filters,
),
self.test_wrong_cert_tls12,
self.test_wrong_cert_tls13,
)
# Be careful with the number of threads here.
# Too many can result in failing tests.
threads = []
for num in range(5):
for func in funcs:
threads.append(Thread(target=func))

warnings_filters = sys.flags.context_aware_warnings
global USE_SAME_TEST_CONTEXT
USE_SAME_TEST_CONTEXT = True
try:
for func in (
self.test_echo,
self.test_alpn_protocols,
self.test_getpeercert,
self.test_crl_check,
functools.partial(
self.test_check_hostname_idn,
warnings_filters=warnings_filters,
),
self.test_wrong_cert_tls12,
self.test_wrong_cert_tls13,
):
# Be careful with the number of threads here.
# Too many can result in failing tests.
for num in range(5):
with self.subTest(func=func, num=num):
threads.append(Thread(target=func))

with threading_helper.catch_threading_exception() as cm:
for thread in threads:
with self.subTest(thread=thread):
thread.start()

for thread in threads:
with self.subTest(thread=thread):
thread.join()
if cm.exc_value is not None:
# Some threads can skip their test
if not isinstance(cm.exc_value, unittest.SkipTest):
raise cm.exc_value
finally:
USE_SAME_TEST_CONTEXT = False
with threading_helper.catch_threading_exception() as cm:
with threading_helper.start_threads(threads):
pass
if cm.exc_value is not None:
# Some threads can skip their test
if not isinstance(cm.exc_value, unittest.SkipTest):
raise cm.exc_value
Comment on lines +3028 to +3034
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use threading_helper.run_concurrently for this instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice helper, but it is not applicable here. It runs the same function in multiple threads.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't that what we want to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it runs several different tests concurrently multiple times.


def test_getpeercert(self):
if support.verbose:
Expand Down
Loading