commit 25665b365c2f8f3a81866f500da725e59be10389
parent 6f1601a1b94e6ea724d8436600c64760525d1d2b
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri, 11 Oct 2024 09:45:44 +0800
test(tui_spec): better prevent race between paste and input (#30751)
Problem:
Using a single RPC request to child server isn't enough to prevent race
between nvim_paste and nvim_input.
Solution:
Ensure both child client and child server have processed pending events
by sending an empty DCS response to the child client and waiting for
TermResponse autocommand on the child server.
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
@@ -87,6 +87,21 @@ describe('TUI', function()
end)
end
+ -- Ensure both child client and child server have processed pending events.
+ local function poke_both_eventloop()
+ child_exec_lua([[
+ _G.termresponse = nil
+ vim.api.nvim_create_autocmd('TermResponse', {
+ once = true,
+ callback = function(ev) _G.termresponse = ev.data end,
+ })
+ ]])
+ feed_data('\027P0$r\027\\')
+ retry(nil, nil, function()
+ eq('\027P0$r', child_exec_lua('return _G.termresponse'))
+ end)
+ end
+
it('rapid resize #7572 #7628', function()
-- Need buffer rows to provoke the behavior.
feed_data(':edit test/functional/fixtures/bigfile.txt\n')
@@ -975,6 +990,7 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
feed_data('\027[201~') -- End paste.
+ poke_both_eventloop()
screen:expect_unchanged()
feed_data('\027[27u') -- ESC: go to Normal mode.
wait_for_mode('n')
@@ -1157,6 +1173,7 @@ describe('TUI', function()
feed_data('\027[200~line 1\nline 2\n')
wait_for_mode('c')
feed_data('line 3\nline 4\n\027[201~')
+ poke_both_eventloop()
wait_for_mode('c')
screen:expect([[
foo |
@@ -1201,6 +1218,7 @@ describe('TUI', function()
expect_cmdline('"stuff 1 more"')
-- End the paste sequence.
feed_data('\027[201~')
+ poke_both_eventloop()
expect_cmdline('"stuff 1 more"')
feed_data(' typed')
expect_cmdline('"stuff 1 more typed"')
@@ -1324,6 +1342,7 @@ describe('TUI', function()
feed_data('ccc!') -- This chunk is cancelled.
expect_child_buf_lines({ 'aaabbb' })
feed_data('ddd\027[201~') -- This chunk is ignored.
+ poke_both_eventloop()
expect_child_buf_lines({ 'aaabbb' })
feed_data('\027[27u')
wait_for_mode('n')
@@ -1542,6 +1561,7 @@ describe('TUI', function()
]])
-- Send isolated "stop paste" sequence.
feed_data('\027[201~') -- phase 3
+ poke_both_eventloop()
screen:expect_unchanged()
local _, rv = child_session:request('nvim_exec_lua', [[return _G.paste_phases]], {})
-- In rare cases there may be multiple chunks of phase 2 because of timing.