Skip to content

Commit 6a2c5a7

Browse files
committed
patch 8.2.0533: tests using term_wait() can still be flaky
Problem: Tests using term_wait() can still be flaky. Solution: Increase the wait time when rerunning a test. (James McCoy, closes #5899) Halve the initial times to make tests run faster when there is no rerun.
1 parent 7035fd9 commit 6a2c5a7

36 files changed

Lines changed: 175 additions & 167 deletions

src/testdir/term_util.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ func StopShellInTerminal(buf)
2424
call WaitFor({-> job_status(job) == "dead"})
2525
endfunc
2626

27+
" Wrapper around term_wait() to allow more time for re-runs of flaky tests
28+
" The second argument is the minimum time to wait in msec, 10 if omitted.
29+
func TermWait(buf, ...)
30+
let wait_time = a:0 ? a:1 : 10
31+
if g:run_nr == 2
32+
let wait_time *= 4
33+
elseif g:run_nr > 2
34+
let wait_time *= 10
35+
endif
36+
call term_wait(a:buf, wait_time)
37+
38+
" In case it wasn't set yet.
39+
let g:test_is_flaky = 1
40+
endfunc
41+
2742
" Run Vim with "arguments" in a new terminal window.
2843
" By default uses a size of 20 lines and 75 columns.
2944
" Returns the buffer number of the terminal.
@@ -82,7 +97,7 @@ func RunVimInTerminal(arguments, options)
8297
let cols = term_getsize(buf)[1]
8398
endif
8499

85-
call term_wait(buf)
100+
call TermWait(buf)
86101

87102
" Wait for "All" or "Top" of the ruler to be shown in the last line or in
88103
" the status line of the last window. This can be quite slow (e.g. when

src/testdir/test_arglist.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func Test_quit_with_arglist()
518518
call term_sendkeys(buf, ":set nomore\n")
519519
call term_sendkeys(buf, ":args a b c\n")
520520
call term_sendkeys(buf, ":quit\n")
521-
call term_wait(buf)
521+
call TermWait(buf)
522522
call WaitForAssert({-> assert_match('^E173:', term_getline(buf, 6))})
523523
call StopVimInTerminal(buf)
524524

@@ -527,16 +527,16 @@ func Test_quit_with_arglist()
527527
call term_sendkeys(buf, ":set nomore\n")
528528
call term_sendkeys(buf, ":args a b c\n")
529529
call term_sendkeys(buf, ":confirm quit\n")
530-
call term_wait(buf)
530+
call TermWait(buf)
531531
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
532532
\ term_getline(buf, 6))})
533533
call term_sendkeys(buf, "N")
534-
call term_wait(buf)
534+
call TermWait(buf)
535535
call term_sendkeys(buf, ":confirm quit\n")
536536
call WaitForAssert({-> assert_match('^\[Y\]es, (N)o: *$',
537537
\ term_getline(buf, 6))})
538538
call term_sendkeys(buf, "Y")
539-
call term_wait(buf)
539+
call TermWait(buf)
540540
call WaitForAssert({-> assert_equal("finished", term_getstatus(buf))})
541541
only!
542542
" When this test fails, swap files are left behind which breaks subsequent

src/testdir/test_autocmd.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,9 +1761,9 @@ function s:Before_test_dirchanged()
17611761
augroup END
17621762
let s:li = []
17631763
let s:dir_this = getcwd()
1764-
let s:dir_foo = s:dir_this . '/foo'
1764+
let s:dir_foo = s:dir_this . '/Xfoo'
17651765
call mkdir(s:dir_foo)
1766-
let s:dir_bar = s:dir_this . '/bar'
1766+
let s:dir_bar = s:dir_this . '/Xbar'
17671767
call mkdir(s:dir_bar)
17681768
endfunc
17691769

@@ -2291,9 +2291,9 @@ func Test_autocmd_SafeState()
22912291
call WaitForAssert({-> assert_match('^xxx', term_getline(buf, 6))}, 1000)
22922292

22932293
call term_sendkeys(buf, ":let g:again = ''\<CR>:call CallTimer()\<CR>")
2294-
call term_wait(buf, 100)
2294+
call TermWait(buf, 50)
22952295
call term_sendkeys(buf, ":\<CR>")
2296-
call term_wait(buf, 100)
2296+
call TermWait(buf, 50)
22972297
call term_sendkeys(buf, ":echo g:again\<CR>")
22982298
call WaitForAssert({-> assert_match('xtx', term_getline(buf, 6))}, 1000)
22992299

@@ -2317,7 +2317,7 @@ func Test_autocmd_CmdWinEnter()
23172317
let buf = RunVimInTerminal('-S '.filename, #{rows: 6})
23182318

23192319
call term_sendkeys(buf, "q:")
2320-
call term_wait(buf)
2320+
call TermWait(buf)
23212321
call term_sendkeys(buf, ":echo b:dummy_var\<cr>")
23222322
call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 2000)
23232323
call term_sendkeys(buf, ":echo &buftype\<cr>")

src/testdir/test_balloon.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ func Test_balloon_eval_term()
3232

3333
" Check that the balloon shows up after a mouse move
3434
let buf = RunVimInTerminal('-S XTest_beval', {'rows': 10, 'cols': 50})
35-
call term_wait(buf, 100)
35+
call TermWait(buf, 50)
3636
call term_sendkeys(buf, 'll')
3737
call term_sendkeys(buf, ":call Trigger()\<CR>")
3838
call VerifyScreenDump(buf, 'Test_balloon_eval_term_01', {})
3939

4040
" Make sure the balloon still shows after 'updatetime' passed and CursorHold
4141
" was triggered.
42-
call term_wait(buf, 300)
42+
call TermWait(buf, 150)
4343
call VerifyScreenDump(buf, 'Test_balloon_eval_term_01a', {})
4444

4545
" clean up
@@ -57,7 +57,7 @@ func Test_balloon_eval_term_visual()
5757

5858
" Check that the balloon shows up after a mouse move
5959
let buf = RunVimInTerminal('-S XTest_beval_visual', {'rows': 10, 'cols': 50})
60-
call term_wait(buf, 100)
60+
call TermWait(buf, 50)
6161
call VerifyScreenDump(buf, 'Test_balloon_eval_term_02', {})
6262

6363
" clean up

src/testdir/test_bufline.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func Test_appendbufline_redraw()
164164
END
165165
call writefile(lines, 'XscriptMatchCommon')
166166
let buf = RunVimInTerminal('-S XscriptMatchCommon', #{rows: 10})
167-
call term_wait(buf)
167+
call TermWait(buf)
168168
call VerifyScreenDump(buf, 'Test_appendbufline_1', {})
169169

170170
call StopVimInTerminal(buf)

src/testdir/test_channel.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ func Test_write_to_buffer_and_scroll()
10621062
END
10631063
call writefile(lines, 'XtestBufferScroll')
10641064
let buf = RunVimInTerminal('-S XtestBufferScroll', #{rows: 10})
1065-
call term_wait(buf, 100)
1065+
call TermWait(buf, 50)
10661066
call VerifyScreenDump(buf, 'Test_job_buffer_scroll_1', {})
10671067

10681068
" clean up

src/testdir/test_cmdline.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ func Test_verbose_option()
947947
call writefile(lines, 'XTest_verbose')
948948

949949
let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
950-
call term_wait(buf, 100)
950+
call TermWait(buf, 50)
951951
call term_sendkeys(buf, ":DoSomething\<CR>")
952952
call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
953953

@@ -1024,7 +1024,7 @@ func Test_cmdwin_restore()
10241024
call writefile(lines, 'XTest_restore')
10251025

10261026
let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
1027-
call term_wait(buf, 100)
1027+
call TermWait(buf, 50)
10281028
call term_sendkeys(buf, "q:")
10291029
call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
10301030

@@ -1146,7 +1146,7 @@ func Test_cmdlineclear_tabenter()
11461146

11471147
call writefile(lines, 'XtestCmdlineClearTabenter')
11481148
let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
1149-
call term_wait(buf, 50)
1149+
call TermWait(buf, 25)
11501150
" in one tab make the command line higher with CTRL-W -
11511151
call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
11521152
call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})

src/testdir/test_conceal.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func Test_conceal_resize_term()
147147
call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
148148

149149
call win_execute(buf->win_findbuf()[0], 'wincmd +')
150-
call term_wait(buf)
150+
call TermWait(buf)
151151
call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
152152

153153
" clean up

src/testdir/test_cursorline.vim

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,61 +135,61 @@ func Test_cursorline_screenline()
135135
call writefile(lines, filename)
136136
" basic test
137137
let buf = RunVimInTerminal('-S '. filename, #{rows: 20})
138-
call term_wait(buf)
138+
call TermWait(buf)
139139
call VerifyScreenDump(buf, 'Test_'. filename. '_1', {})
140140
call term_sendkeys(buf, "fagj")
141-
call term_wait(buf)
141+
call TermWait(buf)
142142
call VerifyScreenDump(buf, 'Test_'. filename. '_2', {})
143143
call term_sendkeys(buf, "gj")
144-
call term_wait(buf)
144+
call TermWait(buf)
145145
call VerifyScreenDump(buf, 'Test_'. filename. '_3', {})
146146
call term_sendkeys(buf, "gj")
147-
call term_wait(buf)
147+
call TermWait(buf)
148148
call VerifyScreenDump(buf, 'Test_'. filename. '_4', {})
149149
call term_sendkeys(buf, "gj")
150-
call term_wait(buf)
150+
call TermWait(buf)
151151
call VerifyScreenDump(buf, 'Test_'. filename. '_5', {})
152152
call term_sendkeys(buf, "gj")
153-
call term_wait(buf)
153+
call TermWait(buf)
154154
call VerifyScreenDump(buf, 'Test_'. filename. '_6', {})
155155
" test with set list and cursorlineopt containing number
156156
call term_sendkeys(buf, "gg0")
157157
call term_sendkeys(buf, ":set list cursorlineopt+=number listchars=space:-\<cr>")
158158
call VerifyScreenDump(buf, 'Test_'. filename. '_7', {})
159159
call term_sendkeys(buf, "fagj")
160-
call term_wait(buf)
160+
call TermWait(buf)
161161
call VerifyScreenDump(buf, 'Test_'. filename. '_8', {})
162162
call term_sendkeys(buf, "gj")
163-
call term_wait(buf)
163+
call TermWait(buf)
164164
call VerifyScreenDump(buf, 'Test_'. filename. '_9', {})
165165
call term_sendkeys(buf, "gj")
166-
call term_wait(buf)
166+
call TermWait(buf)
167167
call VerifyScreenDump(buf, 'Test_'. filename. '_10', {})
168168
call term_sendkeys(buf, "gj")
169-
call term_wait(buf)
169+
call TermWait(buf)
170170
call VerifyScreenDump(buf, 'Test_'. filename. '_11', {})
171171
call term_sendkeys(buf, "gj")
172-
call term_wait(buf)
172+
call TermWait(buf)
173173
call VerifyScreenDump(buf, 'Test_'. filename. '_12', {})
174174
if exists("+foldcolumn") && exists("+signcolumn") && exists("+breakindent")
175175
" test with set foldcolumn signcoloumn and breakindent
176176
call term_sendkeys(buf, "gg0")
177177
call term_sendkeys(buf, ":set breakindent foldcolumn=2 signcolumn=yes\<cr>")
178178
call VerifyScreenDump(buf, 'Test_'. filename. '_13', {})
179179
call term_sendkeys(buf, "fagj")
180-
call term_wait(buf)
180+
call TermWait(buf)
181181
call VerifyScreenDump(buf, 'Test_'. filename. '_14', {})
182182
call term_sendkeys(buf, "gj")
183-
call term_wait(buf)
183+
call TermWait(buf)
184184
call VerifyScreenDump(buf, 'Test_'. filename. '_15', {})
185185
call term_sendkeys(buf, "gj")
186-
call term_wait(buf)
186+
call TermWait(buf)
187187
call VerifyScreenDump(buf, 'Test_'. filename. '_16', {})
188188
call term_sendkeys(buf, "gj")
189-
call term_wait(buf)
189+
call TermWait(buf)
190190
call VerifyScreenDump(buf, 'Test_'. filename. '_17', {})
191191
call term_sendkeys(buf, "gj")
192-
call term_wait(buf)
192+
call TermWait(buf)
193193
call VerifyScreenDump(buf, 'Test_'. filename. '_18', {})
194194
endif
195195

src/testdir/test_debugger.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ source check.vim
88
" If the expected output argument is supplied, then check for it.
99
func RunDbgCmd(buf, cmd, ...)
1010
call term_sendkeys(a:buf, a:cmd . "\r")
11-
call term_wait(a:buf, 20)
11+
call TermWait(a:buf)
1212

1313
if a:0 != 0
1414
" Verify the expected output

0 commit comments

Comments
 (0)