1
0
forked from aniani/vim
Files
vim/src/testdir/test_balloon.vim
Yee Cheng Chin e70587dbdb patch 9.1.1110: Vim tests are slow and flaky
Problem:  Vim tests are slow and flaky at the same time due to reliance
          on timeouts which are unreliable.
Solution: improve Vim test performance and reduce flakiness
          (Yee Cheng Chin)

A lot of Vim tests currently rely on waiting a specific amount of time
before asserting a condition. This is bad because 1) it is slow, as the
timeout is hardcoded, 2) it's unreliable as a resource-starved runner
may overshoot the timeout. Also, there are a lot of builtin sleep
commands in commonly used utilities like VerifyScreenDump and WaitFor()
which leads to a lot of unnecessary idle time.

Fix these issues by doing the following:
1. Make utilities like VerifyScreenDump and WaitFor use the lowest wait
   time possible (1 ms). This essentially turns it into a spin wait. On
   fast machines, these will finish very quickly. For existing tests
   that had an implicit reliance on the old timeouts (e.g.
   VerifyScreenDump had a 50ms wait before), fix the tests to wait that
   specific amount explicitly.
2. Fix tests that sleep or wait for long amounts of time to instead
   explicitly use a callback mechanism to be notified when a child
   terminal job has finished. This allows the test to only take as much
   time as possible instead of having to hard code an unreliable
   timeout.

With these fixes, tests should 1) completely quickly on fast machines,
and 2) on slow machines they will still run to completion albeit slowly.
Note that previoulsy both were not true. The hardcoded timeouts meant
that on fast machines the tests were mostly idling wasting time, whereas
on slow machines, the timeouts often were not generous enough to allow
them to run to completion.

closes: #16615

Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-02-13 20:55:45 +01:00

94 lines
2.9 KiB
VimL

" Tests for 'balloonevalterm'.
" A few tests only work in the terminal.
source check.vim
CheckNotGui
CheckFeature balloon_eval_term
source screendump.vim
CheckScreendump
let s:common_script =<< trim [CODE]
call setline(1, ["one one one", "two tXo two", "three three three"])
set balloonevalterm balloonexpr=MyBalloonExpr()..s:trailing balloondelay=100
let s:trailing = '<' " check that script context is set
func MyBalloonExpr()
return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ":\n" .. v:beval_text
endfun
redraw
[CODE]
func Test_balloon_eval_term()
" Use <Ignore> after <MouseMove> to return from vgetc() without removing
" the balloon.
let xtra_lines =<< trim [CODE]
set updatetime=300
au CursorHold * echo 'hold fired'
func Trigger()
call test_setmouse(2, 6)
call feedkeys("\<MouseMove>\<Ignore>", "xt")
endfunc
[CODE]
call writefile(s:common_script + xtra_lines, 'XTest_beval', 'D')
" Check that the balloon shows up after a mouse move
let buf = RunVimInTerminal('-S XTest_beval', {'rows': 10, 'cols': 50})
call TermWait(buf, 50)
call term_sendkeys(buf, 'll')
call term_sendkeys(buf, ":call Trigger()\<CR>")
sleep 150m " Wait for balloon to show up (100ms balloondelay time)
call VerifyScreenDump(buf, 'Test_balloon_eval_term_01', {})
" Make sure the balloon still shows after 'updatetime' passed and CursorHold
" was triggered.
call TermWait(buf, 150)
call VerifyScreenDump(buf, 'Test_balloon_eval_term_01a', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_balloon_eval_term_visual()
" Use <Ignore> after <MouseMove> to return from vgetc() without removing
" the balloon.
call writefile(s:common_script + [
\ 'call test_setmouse(3, 6)',
\ 'call feedkeys("3Gevfr\<MouseMove>\<Ignore>", "xt")',
\ ], 'XTest_beval_visual', 'D')
" Check that the balloon shows up after a mouse move
let buf = RunVimInTerminal('-S XTest_beval_visual', {'rows': 10, 'cols': 50})
call TermWait(buf, 50)
call VerifyScreenDump(buf, 'Test_balloon_eval_term_02', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_balloon_eval_term_rightleft()
CheckFeature rightleft
" Use <Ignore> after <MouseMove> to return from vgetc() without removing
" the balloon.
let xtra_lines =<< trim [CODE]
set rightleft
func Trigger()
call test_setmouse(2, 50 + 1 - 6)
call feedkeys("\<MouseMove>\<Ignore>", "xt")
endfunc
[CODE]
call writefile(s:common_script + xtra_lines, 'XTest_beval_rl', 'D')
" Check that the balloon shows up after a mouse move
let buf = RunVimInTerminal('-S XTest_beval_rl', {'rows': 10, 'cols': 50})
call TermWait(buf, 50)
call term_sendkeys(buf, 'll')
call term_sendkeys(buf, ":call Trigger()\<CR>")
call VerifyScreenDump(buf, 'Test_balloon_eval_term_03', {})
" clean up
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab