|
| 1 | +import os |
| 2 | +import re |
1 | 3 | import unittest |
| 4 | +from test.support import os_helper |
| 5 | +from multiprocessing.util import _SUN_PATH_MAX |
2 | 6 | from test._test_multiprocessing import install_tests_in_module_dict |
| 7 | +from test.support import script_helper |
3 | 8 |
|
4 | 9 | install_tests_in_module_dict(globals(), 'forkserver', exclude_types=True) |
5 | 10 |
|
| 11 | + |
| 12 | +class TestForkServerConfiguration(unittest.TestCase): |
| 13 | + def test_respect_sun_path_max(self): |
| 14 | + # Ensure that the calculation for temporary filepath lengths is correct. |
| 15 | + # See https://github.com/python/cpython/issues/149527. |
| 16 | + |
| 17 | + cmd = '''if 1: |
| 18 | + from multiprocessing.connection import arbitrary_address |
| 19 | + from multiprocessing.util import get_temp_dir |
| 20 | + if __name__ == "__main__": |
| 21 | + print(get_temp_dir()) |
| 22 | + print(arbitrary_address("AF_UNIX")) |
| 23 | + ''' |
| 24 | + with os_helper.temp_dir() as root: |
| 25 | + self.assertLess(len(root), _SUN_PATH_MAX) |
| 26 | + _, out, _ = script_helper.assert_python_ok('-c', cmd, TMPDIR=root) |
| 27 | + res = out.decode().strip().splitlines() |
| 28 | + self.assertEqual(len(res), 2) |
| 29 | + |
| 30 | + temp_pymp = res[0] |
| 31 | + temp_pymp_regex = os.path.join(re.escape(root), r"pymp-\w{8}") |
| 32 | + self.assertRegex(temp_pymp, temp_pymp_regex) |
| 33 | + |
| 34 | + temp_sock = res[1] |
| 35 | + temp_sock_regex = os.path.join(temp_pymp_regex, r"sock-[0-9a-fA-F]{12}") |
| 36 | + self.assertRegex(temp_sock, temp_sock_regex) |
| 37 | + |
| 38 | + |
6 | 39 | if __name__ == '__main__': |
7 | 40 | unittest.main() |
0 commit comments