timer_spec: fix/harden flaky tests (#11080)

Those are flaky when using luacov (which causes reproducible slowness).

E.g.:

    [  ERROR   ] test/functional\eval\timer_spec.lua @ 105: timers can invoke redraw in blocking getchar() call
    test\functional\ui\screen.lua:587: Row 3 did not match.
    Expected:
      |ITEM 1                                  |
      |ITEM 2                                  |
      |*{1:~                                       }|
      |{1:~                                       }|
      |{1:~                                       }|
      |^                                        |
    Actual:
      |ITEM 1                                  |
      |ITEM 2                                  |
      |*ITEM 3                                  |
      |{1:~                                       }|
      |{1:~                                       }|
      |^                                        |
This commit is contained in:
Daniel Hahler 2019-09-24 08:55:27 +02:00 committed by GitHub
parent 2476a97ced
commit 0ab7da8561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -111,7 +111,13 @@ describe('timers', function()
curbufmeths.set_lines(0, -1, true, {"ITEM 1", "ITEM 2"})
source([[
let g:cont = 0
func! AddItem(timer)
if !g:cont
return
endif
call timer_stop(a:timer)
call nvim_buf_set_lines(0, 2, 2, v:true, ['ITEM 3'])
" Meant to test for what Vim tests in Test_peek_and_get_char.
@ -121,7 +127,7 @@ describe('timers', function()
endfunc
]])
nvim_async("command", "let g:c2 = getchar()")
nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem')")
nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})")
screen:expect([[
ITEM 1 |
@ -131,6 +137,7 @@ describe('timers', function()
{1:~ }|
^ |
]])
nvim_async("command", "let g:cont = 1")
screen:expect([[
ITEM 1 |
@ -222,12 +229,17 @@ describe('timers', function()
source([[
let g:val = 0
func! MyHandler(timer)
while !g:val
return
endwhile
call timer_stop(a:timer)
echo "evil"
redraw
let g:val = 1
let g:val = 2
endfunc
]])
command("call timer_start(100, 'MyHandler', {'repeat': 1})")
command("call timer_start(100, 'MyHandler', {'repeat': -1})")
feed(":good")
screen:expect([[
|
@ -237,6 +249,7 @@ describe('timers', function()
{0:~ }|
:good^ |
]])
command('let g:val = 1')
screen:expect{grid=[[
|
@ -247,6 +260,6 @@ describe('timers', function()
:good^ |
]], intermediate=true, timeout=load_adjust(200)}
eq(1, eval('g:val'))
eq(2, eval('g:val'))
end)
end)