Skip to content

Commit aae1bfb

Browse files
committed
patch 9.1.1090: tests: test_terminwscroll_topline2 unreliable
Problem: tests: test_terminwscroll_topline2 unreliable (Yee Cheng Chin) Solution: instead of using term_wait() with a specific time, use terminal-api and to wait until the terminal is finished call a terminal callback function when finished printing, instead of using term_wait(), with a defined time, which caused timeouts on CI with the macos runners Unfortunately I couldn't figure out how to call the terminal-api on Windows, so skip the test on Windows. cmd.com echo didn's seem to work and neither did trying to use python, but perhaps it was just me fighting with the terminal quoting rules 🤷 related: #16599 related: #16552 Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 6f14ef4 commit aae1bfb

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

src/testdir/test_terminal2.vim

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,16 @@ func Test_termwinscroll_topline()
290290
endfunc
291291

292292
func Test_termwinscroll_topline2()
293+
" calling the terminal API doesn't work on Windows
294+
CheckNotMSWindows
293295
let g:test_is_flaky = 1
296+
let g:print_complete = 0
297+
func! Tapi_print_complete(bufnum, arglist)
298+
let g:print_complete = 1
299+
endfunc
300+
294301
set termwinscroll=50000 mouse=a
295-
if !has('win32')
296-
set shell=sh
297-
endif
302+
set shell=sh
298303
let norm_winid = win_getid()
299304
terminal
300305
call assert_equal(2, winnr('$'))
@@ -304,26 +309,26 @@ func Test_termwinscroll_topline2()
304309

305310
let num1 = &termwinscroll / 1000 * 999
306311
call writefile(range(num1), 'Xtext', 'D')
307-
if has('win32')
308-
call term_sendkeys(buf, "type Xtext\<CR>")
309-
else
310-
call term_sendkeys(buf, "cat Xtext\<CR>")
311-
endif
312+
call term_sendkeys(buf, "cat Xtext\<CR>")
313+
call term_sendkeys(buf, 'printf ''\033]51;["call", "Tapi_print_complete", []]\007''' .. "\<cr>")
312314
let rows = term_getsize(buf)[0]
313-
" It may take a while to finish on a slow system
314-
call term_wait(buf, 2000 * g:run_nr)
315-
" On MS-Windows there is an empty line, check both last line and above it.
315+
let cnt = 0
316+
while !g:print_complete && cnt <= 1000
317+
" max number of runs
318+
let cnt += 1
319+
" sleep a bit, to give the the terminal some time to finish
320+
321+
" It may take a while to finish on a slow system
322+
" so wait a bit and handle the callback
323+
call term_wait(buf)
324+
endwhile
316325
call WaitForAssert({-> assert_match(string(num1 - 1), term_getline(buf, rows - 1) .. '\|' .. term_getline(buf, rows - 2))})
317326
call feedkeys("\<C-W>N", 'xt')
318327
call feedkeys("i", 'xt')
319328

320329
let num2 = &termwinscroll / 1000 * 8
321330
call writefile(range(num2), 'Xtext', 'D')
322-
if has('win32')
323-
call term_sendkeys(buf, "timeout /t 2 && type Xtext\<CR>")
324-
else
325-
call term_sendkeys(buf, "sleep 2; cat Xtext\<CR>")
326-
endif
331+
call term_sendkeys(buf, "sleep 2; cat Xtext\<CR>")
327332
let winrow = get(get(filter(getwininfo(), 'v:val.winid == norm_winid'), 0, {}), 'winrow', -1)
328333

329334
call test_setmouse(winrow, 1)
@@ -342,6 +347,8 @@ func Test_termwinscroll_topline2()
342347

343348
exe buf . 'bwipe!'
344349
set termwinscroll& mouse& sh&
350+
delfunc Tapi_print_complete
351+
unlet! g:print_complete
345352
endfunc
346353

347354
" Resizing the terminal window caused an ml_get error.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1090,
707709
/**/
708710
1089,
709711
/**/

0 commit comments

Comments
 (0)