diff options
author | Miro HronĨok <miro@hroncok.cz> | 2022-08-03 23:19:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 23:19:36 (GMT) |
commit | fe23c0061d9c72527ad57a8c965d8161b00f500e (patch) | |
tree | 889c8cf93b1a1cae3d4414cc199d1b2263898187 /Lib/test/test_re.py | |
parent | dc2757accd8413abfc24d7acf06d8bf233d01534 (diff) | |
download | cpython-fe23c0061d9c72527ad57a8c965d8161b00f500e.zip cpython-fe23c0061d9c72527ad57a8c965d8161b00f500e.tar.gz cpython-fe23c0061d9c72527ad57a8c965d8161b00f500e.tar.bz2 |
gh-94675: Add a regression test for rjsmin re slowdown (GH-94685)
Adds a regression test for an re slowdown observed by rjsmin.
Uses multiprocessing to kill the test after SHORT_TIMEOUT.
Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 9f734d4..3f0f84e 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,6 +1,7 @@ from test.support import (gc_collect, bigmemtest, _2G, cpython_only, captured_stdout, - check_disallow_instantiation, is_emscripten, is_wasi) + check_disallow_instantiation, is_emscripten, is_wasi, + SHORT_TIMEOUT) import locale import re import string @@ -11,6 +12,14 @@ import warnings from re import Scanner from weakref import proxy +# some platforms lack working multiprocessing +try: + import _multiprocessing +except ImportError: + multiprocessing = None +else: + import multiprocessing + # Misc tests from Tim Peters' re.doc # WARNING: Don't change details in these tests if you don't know @@ -2407,6 +2416,26 @@ class ReTests(unittest.TestCase): self.assertTrue(template_re1.match('ahoy')) self.assertFalse(template_re1.match('nope')) + @unittest.skipIf(multiprocessing is None, 'test requires multiprocessing') + def test_regression_gh94675(self): + pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*' + r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))' + r'[^/\[]*)*/))((((//[^\n]*)?[\n])' + r'([\000-\040]|(/\*[^*]*\*+' + r'([^/*]\*+)*/))*)+(?=[^\000-\040);\]}]))') + input_js = '''a(function() { + /////////////////////////////////////////////////////////////////// + });''' + p = multiprocessing.Process(target=pattern.sub, args=('', input_js)) + p.start() + p.join(SHORT_TIMEOUT) + try: + self.assertFalse(p.is_alive(), 'pattern.sub() timed out') + finally: + if p.is_alive(): + p.terminate() + p.join() + def get_debug_out(pat): with captured_stdout() as out: |