comparison src/testdir/test_search.vim @ 29191:0af5fe160e4e v8.2.5115

patch 8.2.5115: search timeout is overrun with some patterns Commit: https://github.com/vim/vim/commit/616592e0816d2d9f893fcd95e3e1e0fbc5893168 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 17 15:17:10 2022 +0100 patch 8.2.5115: search timeout is overrun with some patterns Problem: Search timeout is overrun with some patterns. Solution: Check for timeout in more places. Make the flag volatile and atomic. Use assert_inrange() to see what happened.
author Bram Moolenaar <Bram@vim.org>
date Fri, 17 Jun 2022 16:30:06 +0200
parents d1e263ecf634
children ca46658481cf
comparison
equal deleted inserted replaced
29190:a4f0e5e61728 29191:0af5fe160e4e
1574 bwipe! 1574 bwipe!
1575 endfunc 1575 endfunc
1576 1576
1577 func Test_search_timeout() 1577 func Test_search_timeout()
1578 new 1578 new
1579 " use a complicated pattern that should be slow with the BT engine
1579 let pattern = '\%#=1a*.*X\@<=b*' 1580 let pattern = '\%#=1a*.*X\@<=b*'
1580 let search_timeout = 0.02 1581
1582 " use a timeout of 50 msec
1583 let search_timeout = 0.05
1584
1585 " fill the buffer so that it takes 15 times the timeout to search
1581 let slow_target_timeout = search_timeout * 15.0 1586 let slow_target_timeout = search_timeout * 15.0
1582 1587
1588 " Fill the buffer with more and more text until searching takes more time
1589 " than slow_target_timeout.
1583 for n in range(40, 400, 30) 1590 for n in range(40, 400, 30)
1584 call setline(1, ['aaa', repeat('abc ', n), 'ccc']) 1591 call setline(1, ['aaa', repeat('abc ', n), 'ccc'])
1585 let start = reltime() 1592 let start = reltime()
1586 call search(pattern, '', 0) 1593 call search(pattern, '', 0)
1587 let elapsed = reltimefloat(reltime(start)) 1594 let elapsed = reltimefloat(reltime(start))
1589 break 1596 break
1590 endif 1597 endif
1591 endfor 1598 endfor
1592 call assert_true(elapsed > slow_target_timeout) 1599 call assert_true(elapsed > slow_target_timeout)
1593 1600
1601 " Check that the timeout kicks in, the time should be less than half of what
1602 " we measured without the timeout. This is permissive, because the timer is
1603 " known to overrun, especially when using valgrind.
1594 let max_time = elapsed / 2.0 1604 let max_time = elapsed / 2.0
1595 let start = reltime() 1605 let start = reltime()
1596 call search(pattern, '', 0, float2nr(search_timeout * 1000)) 1606 call search(pattern, '', 0, float2nr(search_timeout * 1000))
1597 let elapsed = reltimefloat(reltime(start)) 1607 let elapsed = reltimefloat(reltime(start))
1598 call assert_true(elapsed < max_time) 1608 call assert_inrange(search_timeout * 0.9, max_time, elapsed)
1599 1609
1600 bwipe! 1610 bwipe!
1601 endfunc 1611 endfunc
1602 1612
1603 func Test_search_display_pattern() 1613 func Test_search_display_pattern()