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>
diff --git a/src/testdir/test_terminal2.vim b/src/testdir/test_terminal2.vim
index 5c4563c..542f2ec 100644
--- a/src/testdir/test_terminal2.vim
+++ b/src/testdir/test_terminal2.vim
@@ -292,11 +292,6 @@
func Test_termwinscroll_topline2()
" calling the terminal API doesn't work on Windows
CheckNotMSWindows
- let g:test_is_flaky = 1
- let g:print_complete = 0
- func! Tapi_print_complete(bufnum, arglist)
- let g:print_complete = 1
- endfunc
set termwinscroll=50000 mouse=a
set shell=sh
@@ -310,17 +305,15 @@
let num1 = &termwinscroll / 1000 * 999
call writefile(range(num1), 'Xtext', 'D')
call term_sendkeys(buf, "cat Xtext\<CR>")
- call term_sendkeys(buf, 'printf ''\033]51;["call", "Tapi_print_complete", []]\007''' .. "\<cr>")
+ call term_sendkeys(buf, "printf '" .. TermNotifyParentCmd(v:false) .. "'\<cr>")
let rows = term_getsize(buf)[0]
let cnt = 0
- while !g:print_complete && cnt <= 1000
- " max number of runs
+ while !g:child_notification && cnt <= 50000
+ " Spin wait to process the terminal print as quickly as possible. This is
+ " more efficient than calling WaitForChildNotification() as we don't want
+ " to sleep here as the print is I/O-bound.
let cnt += 1
- " sleep a bit, to give the the terminal some time to finish
-
- " It may take a while to finish on a slow system
- " so wait a bit and handle the callback
- call term_wait(buf)
+ call term_wait(buf, 0)
endwhile
call WaitForAssert({-> assert_match(string(num1 - 1), term_getline(buf, rows - 1) .. '\|' .. term_getline(buf, rows - 2))})
call feedkeys("\<C-W>N", 'xt')
@@ -347,8 +340,6 @@
exe buf . 'bwipe!'
set termwinscroll& mouse& sh&
- delfunc Tapi_print_complete
- unlet! g:print_complete
endfunc
" Resizing the terminal window caused an ml_get error.