Skip to content

Commit ee602ea

Browse files
committed
fixup! gh-94675: Add a regression test for rjsmin re slowdown
Use multiprocessing to kill the test after SHORT_TIMEOUT.
1 parent 63f9899 commit ee602ea

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Lib/test/test_re.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from test.support import (gc_collect, bigmemtest, _2G,
22
cpython_only, captured_stdout,
3-
check_disallow_instantiation, is_emscripten, is_wasi)
3+
check_disallow_instantiation, is_emscripten, is_wasi,
4+
SHORT_TIMEOUT)
5+
import multiprocessing
46
import locale
57
import re
68
import string
@@ -2408,7 +2410,6 @@ def test_template_function_and_flag_is_deprecated(self):
24082410
self.assertFalse(template_re1.match('nope'))
24092411

24102412
def test_regression_gh94675(self):
2411-
start = time.perf_counter()
24122413
pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
24132414
r'((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))'
24142415
r'[^/\[]*)*/))((((//[^\n]*)?[\n])'
@@ -2417,10 +2418,15 @@ def test_regression_gh94675(self):
24172418
input_js = '''a(function() {
24182419
///////////////////////////////////////////////////////////////////
24192420
});'''
2420-
_ = pattern.sub('', input_js)
2421-
t = time.perf_counter() - start
2422-
# Without optimization it takes 0.017 second on my computer.
2423-
self.assertLess(t, 0.5)
2421+
p = multiprocessing.Process(target=pattern.sub, args=('', input_js))
2422+
p.start()
2423+
p.join(SHORT_TIMEOUT)
2424+
try:
2425+
self.assertFalse(p.is_alive(), 'pattern.sub() timed out')
2426+
finally:
2427+
if p.is_alive():
2428+
p.terminate()
2429+
p.join()
24242430

24252431

24262432
def get_debug_out(pat):

0 commit comments

Comments
 (0)