test: fix flaky tests in terminal/{buffer,channel}_spec.lua (#37966)

In buffer_spec.lua, wait for a bit more than the refresh delay.
In channel_spec.lua, retry sending lines on Windows.
This commit is contained in:
zeertzjq
2026-02-19 17:57:02 +08:00
committed by GitHub
parent 76db55c137
commit 2605ce9377
2 changed files with 8 additions and 9 deletions

View File

@@ -304,7 +304,7 @@ describe(':terminal buffer', function()
screen:expect_unchanged()
for i = 1, 10 do
eq({ mode = 't', blocking = true }, api.nvim_get_mode())
vim.uv.sleep(10) -- Wait for the previously scheduled refresh timer to arrive
vim.uv.sleep(15) -- Wait for the previously scheduled refresh timer to arrive
feed('j') -- Refresh scheduled for the last 'j' and processed for the one before
screen:expect(([[
tty ready |
@@ -337,7 +337,7 @@ describe(':terminal buffer', function()
screen:expect_unchanged()
for i = 1, 10 do
eq({ mode = 'nt', blocking = true }, api.nvim_get_mode())
vim.uv.sleep(10) -- Wait for the previously scheduled refresh timer to arrive
vim.uv.sleep(15) -- Wait for the previously scheduled refresh timer to arrive
feed('j') -- Refresh scheduled for the last 'j' and processed for the one before
screen:expect(([[
tty ready |

View File

@@ -137,14 +137,13 @@ it('chansend sends lines to terminal channel in proper order', function()
local shells = is_os('win') and { 'cmd.exe', 'pwsh.exe -nop', 'powershell.exe -nop' } or { 'sh' }
for _, sh in ipairs(shells) do
command([[let id = jobstart(']] .. sh .. [[', {'term':v:true})]])
command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]])
screen:expect {
any = [[echo "hello".*echo "world"]],
}
-- On Windows this may fail if the shell hasn't fully started yet, so retry.
t.retry(is_os('win') and 3 or 1, 5000, function()
command([[call chansend(id, ['echo "hello"', 'echo "world"', ''])]])
screen:expect { any = [[echo "hello".*echo "world"]], timeout = 2000 }
end)
command('bdelete!')
screen:expect {
any = '%[No Name%]',
}
screen:expect { any = '%[No Name%]' }
end
end)