| 2866 | @unittest.skip("TODO: RUSTPYTHON; flaky") |
| 2867 | @unittest.skipUnless(support.Py_GIL_DISABLED, "test is only useful if the GIL is disabled") |
| 2868 | def test_ssl_in_multiple_threads(self): |
| 2869 | # See GH-124984: OpenSSL is not thread safe. |
| 2870 | threads = [] |
| 2871 | |
| 2872 | warnings_filters = sys.flags.context_aware_warnings |
| 2873 | global USE_SAME_TEST_CONTEXT |
| 2874 | USE_SAME_TEST_CONTEXT = True |
| 2875 | try: |
| 2876 | for func in ( |
| 2877 | self.test_echo, |
| 2878 | self.test_alpn_protocols, |
| 2879 | self.test_getpeercert, |
| 2880 | self.test_crl_check, |
| 2881 | functools.partial( |
| 2882 | self.test_check_hostname_idn, |
| 2883 | warnings_filters=warnings_filters, |
| 2884 | ), |
| 2885 | self.test_wrong_cert_tls12, |
| 2886 | self.test_wrong_cert_tls13, |
| 2887 | ): |
| 2888 | # Be careful with the number of threads here. |
| 2889 | # Too many can result in failing tests. |
| 2890 | for num in range(5): |
| 2891 | with self.subTest(func=func, num=num): |
| 2892 | threads.append(Thread(target=func)) |
| 2893 | |
| 2894 | with threading_helper.catch_threading_exception() as cm: |
| 2895 | for thread in threads: |
| 2896 | with self.subTest(thread=thread): |
| 2897 | thread.start() |
| 2898 | |
| 2899 | for thread in threads: |
| 2900 | with self.subTest(thread=thread): |
| 2901 | thread.join() |
| 2902 | if cm.exc_value is not None: |
| 2903 | # Some threads can skip their test |
| 2904 | if not isinstance(cm.exc_value, unittest.SkipTest): |
| 2905 | raise cm.exc_value |
| 2906 | finally: |
| 2907 | USE_SAME_TEST_CONTEXT = False |
| 2908 | |
| 2909 | def test_getpeercert(self): |
| 2910 | if support.verbose: |