test: use poke_eventloop() instead of sleep(10) where possible (#19794)

Using sleep(10) to wait for typeahead to finish is flaky, especially on
macOS, where legacy/global_spec.lua has failed several times.
This commit is contained in:
zeertzjq
2022-08-16 15:21:46 +08:00
committed by GitHub
parent a63eea3d23
commit cf3b871fa9
4 changed files with 19 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, feed, source = helpers.clear, helpers.feed, helpers.source
local command = helpers.command
local poke_eventloop = helpers.poke_eventloop
local sleep = helpers.sleep
describe("CTRL-C (mapped)", function()
@@ -57,11 +58,9 @@ describe("CTRL-C (mapped)", function()
it('interrupts :sleep', function()
command('nnoremap <C-C> <Nop>')
feed(':sleep 100<CR>')
-- wait for :sleep to start
sleep(10)
poke_eventloop() -- wait for :sleep to start
feed('foo<C-C>')
-- wait for input buffer to be flushed
sleep(10)
poke_eventloop() -- wait for input buffer to be flushed
feed('i')
screen:expect([[
^ |
@@ -77,10 +76,9 @@ describe("CTRL-C (mapped)", function()
command('nnoremap <C-C> <Nop>')
command('nmap <F2> <Ignore><F2>')
feed('<F2>')
sleep(10)
sleep(10) -- wait for the key to enter typeahead
feed('foo<C-C>')
-- wait for input buffer to be flushed
sleep(10)
poke_eventloop() -- wait for input buffer to be flushed
feed('i')
screen:expect([[
^ |

View File

@@ -6,7 +6,7 @@ local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local meths = helpers.meths
local sleep = helpers.sleep
local poke_eventloop = helpers.poke_eventloop
before_each(clear)
@@ -143,7 +143,7 @@ describe('Ex mode', function()
^ |
]])
feed('<C-C>')
sleep(10) -- Wait for input to be flushed
poke_eventloop() -- Wait for input to be flushed
feed('foo<CR>')
screen:expect([[
Entering Ex mode. Type "visual" to go to Normal mode. |

View File

@@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local exec = helpers.exec
local feed = helpers.feed
local sleep = helpers.sleep
local poke_eventloop = helpers.poke_eventloop
before_each(clear)
@@ -24,7 +24,7 @@ describe(':global', function()
]])
feed(':g/foo/norm :<C-V>;<CR>')
sleep(10) -- Wait for :sleep to start
poke_eventloop() -- Wait for :sleep to start
feed('<C-C>')
screen:expect([[
^foo |
@@ -37,7 +37,7 @@ describe(':global', function()
-- Also test in Ex mode
feed('gQg/foo/norm :<C-V>;<CR>')
sleep(10) -- Wait for :sleep to start
poke_eventloop() -- Wait for :sleep to start
feed('<C-C>')
screen:expect([[
{0: }|

View File

@@ -131,11 +131,11 @@ describe('mapping', function()
command('set selectmode=mouse')
command('nnoremap <LeftDrag> <LeftDrag><Cmd><CR>')
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'press', '', 0, 0, 0)
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'drag', '', 0, 0, 1)
sleep(10)
poke_eventloop()
eq('s', eval('mode()'))
end)
@@ -144,22 +144,22 @@ describe('mapping', function()
command('inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>')
feed('i')
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'press', '', 0, 0, 0)
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'drag', '', 0, 0, 1)
sleep(10)
poke_eventloop()
eq(1, eval('g:dragged'))
eq('v', eval('mode()'))
feed([[<C-\><C-N>]])
command([[inoremap <LeftDrag> <LeftDrag><C-\><C-N>]])
feed('i')
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'press', '', 0, 0, 0)
sleep(10)
poke_eventloop()
meths.input_mouse('left', 'drag', '', 0, 0, 1)
sleep(10)
poke_eventloop()
eq('n', eval('mode()'))
end)