commit d3aae6172ad3b553604bf5ecf51fa071e3c077dd
parent 87276db7f9b2671ed9f416b4484dfc613dd3a83e
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed, 21 Jan 2026 08:41:00 +0800
test: fix flaky tests (#37478)
* test(core/channels_spec): fix flaky test
Always use expect_stdout() to check PTY output.
* test(autocmd/termxx_spec): fix flaky test
Usually the Ctrl-C cancels the following :qa!, but sometimes it doesn't,
and Nvim exits before feed() returns. Instead make sure that :qa! always
reaches Nvim and use expect_exit().
Diffstat:
2 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua
@@ -166,7 +166,9 @@ describe('autocmd TermClose', function()
retry(nil, nil, function()
eq('3', eval('g:abuf'))
end)
- feed('<c-c>:qa!<cr>')
+ feed('<c-c>')
+ n.poke_eventloop() -- Wait for input to be flushed
+ n.expect_exit(1000, feed, ':qa!<cr>')
end)
it('exposes v:event.status', function()
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua
@@ -186,28 +186,19 @@ describe('channels', function()
eq({ 'notification', 'stdout', { id, { "OnPrint:[1, ['howdy'], 'stdin']" } } }, next_msg())
end)
- local function expect_twoline(id, stream, line1, line2, nobr)
- local msg = next_msg()
- local joined = nobr and { line1 .. line2 } or { line1, line2 }
- if not pcall(eq, { 'notification', stream, { id, joined } }, msg) then
- local sep = (not nobr) and '' or nil
- eq({ 'notification', stream, { id, { line1, sep } } }, msg)
- eq({ 'notification', stream, { id, { line2 } } }, next_msg())
- end
- end
-
-- Helper to accumulate PTY stdout data until expected string is received.
-- PTY reads are non-atomic and may deliver data in chunks.
local function expect_stdout(id, expected)
local accumulated = ''
while #accumulated < #expected do
- local msg = next_msg()
+ local msg = next_msg(1000)
+ if not msg then
+ break
+ end
eq('notification', msg[1])
eq('stdout', msg[2])
eq(id, msg[3][1])
- for _, chunk in ipairs(msg[3][2]) do
- accumulated = accumulated .. chunk
- end
+ accumulated = accumulated .. table.concat(msg[3][2], '\n')
end
eq(expected, accumulated)
end
@@ -239,32 +230,28 @@ describe('channels', function()
ok(id > 0)
command("call chansend(id, 'TEXT\n')")
- expect_twoline(id, 'stdout', 'TEXT\r', "[1, ['TEXT', ''], 'stdin']")
+ expect_stdout(id, "TEXT\r\n[1, ['TEXT', ''], 'stdin']")
command('call chansend(id, 0z426c6f6273210a)')
- expect_twoline(id, 'stdout', 'Blobs!\r', "[1, ['Blobs!', ''], 'stdin']")
+ expect_stdout(id, "Blobs!\r\n[1, ['Blobs!', ''], 'stdin']")
command("call chansend(id, 'neovan')")
expect_stdout(id, 'neovan')
command("call chansend(id, '\127\127im\n')")
- expect_twoline(id, 'stdout', '\b \b\b \bim\r', "[1, ['neovim', ''], 'stdin']")
+ expect_stdout(id, "\b \b\b \bim\r\n[1, ['neovim', ''], 'stdin']")
command("call chansend(id, 'incomplet\004')")
local bsdlike = is_os('bsd') or is_os('mac')
local extra = bsdlike and '^D\008\008' or ''
- expect_twoline(id, 'stdout', 'incomplet' .. extra, "[1, ['incomplet'], 'stdin']", true)
+ expect_stdout(id, 'incomplet' .. extra .. "[1, ['incomplet'], 'stdin']")
command("call chansend(id, '\004')")
- if bsdlike then
- expect_twoline(id, 'stdout', extra, "[1, [''], 'stdin']", true)
- else
- eq({ 'notification', 'stdout', { id, { "[1, [''], 'stdin']" } } }, next_msg())
- end
+ expect_stdout(id, extra .. "[1, [''], 'stdin']")
-- channel is still open
command("call chansend(id, 'hi again!\n')")
- eq({ 'notification', 'stdout', { id, { 'hi again!\r', '' } } }, next_msg())
+ expect_stdout(id, 'hi again!\r\n')
end)
it('stdio channel can use rpc and stderr simultaneously', function()