From cf3b871fa940c42e9c94257118f7d1131ebd362a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 16 Aug 2022 15:21:46 +0800 Subject: 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. --- test/functional/editor/ctrl_c_spec.lua | 12 +++++------- test/functional/legacy/ex_mode_spec.lua | 4 ++-- test/functional/legacy/global_spec.lua | 6 +++--- test/functional/legacy/mapping_spec.lua | 18 +++++++++--------- 4 files changed, 19 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index 60131bf2a4..4548e1aa34 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -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 ') feed(':sleep 100') - -- wait for :sleep to start - sleep(10) + poke_eventloop() -- wait for :sleep to start feed('foo') - -- 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 ') command('nmap ') feed('') - sleep(10) + sleep(10) -- wait for the key to enter typeahead feed('foo') - -- wait for input buffer to be flushed - sleep(10) + poke_eventloop() -- wait for input buffer to be flushed feed('i') screen:expect([[ ^ | diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua index a8f54c6939..f21c47e175 100644 --- a/test/functional/legacy/ex_mode_spec.lua +++ b/test/functional/legacy/ex_mode_spec.lua @@ -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('') - sleep(10) -- Wait for input to be flushed + poke_eventloop() -- Wait for input to be flushed feed('foo') screen:expect([[ Entering Ex mode. Type "visual" to go to Normal mode. | diff --git a/test/functional/legacy/global_spec.lua b/test/functional/legacy/global_spec.lua index 9f4528530c..ff02c41e6c 100644 --- a/test/functional/legacy/global_spec.lua +++ b/test/functional/legacy/global_spec.lua @@ -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 :;') - sleep(10) -- Wait for :sleep to start + poke_eventloop() -- Wait for :sleep to start feed('') screen:expect([[ ^foo | @@ -37,7 +37,7 @@ describe(':global', function() -- Also test in Ex mode feed('gQg/foo/norm :;') - sleep(10) -- Wait for :sleep to start + poke_eventloop() -- Wait for :sleep to start feed('') screen:expect([[ {0: }| diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua index 456acc12b5..c1f23ab0a6 100644 --- a/test/functional/legacy/mapping_spec.lua +++ b/test/functional/legacy/mapping_spec.lua @@ -131,11 +131,11 @@ describe('mapping', function() command('set selectmode=mouse') command('nnoremap ') - 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 let g:dragged = 1') 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([[]]) command([[inoremap ]]) 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) -- cgit