Merge pull request #16294 from zeertzjq/test-fewest-iteration

test: require fewest number of main loop iterations possible
This commit is contained in:
James McCoy 2021-12-18 13:08:28 -05:00 committed by GitHub
commit 8d22049513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err
local feed = helpers.feed local feed = helpers.feed
local sleep = helpers.sleep local sleep = helpers.sleep
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
@ -13,24 +13,22 @@ describe('associated channel is closed and later freed for terminal', function()
it('opened by nvim_open_term() and deleted by :bdelete!', function() it('opened by nvim_open_term() and deleted by :bdelete!', function()
command([[let id = nvim_open_term(0, {})]]) command([[let id = nvim_open_term(0, {})]])
-- channel hasn't been freed yet -- channel hasn't been freed yet
eq("Vim(call):Can't send data to closed stream", exc_exec([[bdelete! | call chansend(id, 'test')]])) eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[bdelete! | call chansend(id, 'test')]]))
-- process free_channel_event -- channel has been freed after one main loop iteration
poke_eventloop() eq("Vim(call):E900: Invalid channel id", pcall_err(command, [[call chansend(id, 'test')]]))
-- channel has been freed
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]]))
end) end)
it('opened by termopen(), exited, and deleted by pressing a key', function() it('opened by termopen(), exited, and deleted by pressing a key', function()
command([[let id = termopen('echo')]]) command([[let id = termopen('echo')]])
sleep(500) sleep(500)
-- process has exited -- process has exited
eq("Vim(call):Can't send data to closed stream", exc_exec([[call chansend(id, 'test')]])) eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[call chansend(id, 'test')]]))
-- delete terminal -- delete terminal
feed('i<CR>') feed('i<CR>')
-- process term_delayed_free and free_channel_event -- need to first process input
poke_eventloop() poke_eventloop()
-- channel has been freed -- channel has been freed after another main loop iteration
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]])) eq("Vim(call):E900: Invalid channel id", pcall_err(command, [[call chansend(id, 'test')]]))
end) end)
-- This indirectly covers #16264 -- This indirectly covers #16264
@ -38,12 +36,10 @@ describe('associated channel is closed and later freed for terminal', function()
command([[let id = termopen('echo')]]) command([[let id = termopen('echo')]])
sleep(500) sleep(500)
-- process has exited -- process has exited
eq("Vim(call):Can't send data to closed stream", exc_exec([[call chansend(id, 'test')]])) eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[call chansend(id, 'test')]]))
-- channel hasn't been freed yet -- channel hasn't been freed yet
eq("Vim(call):Can't send data to closed stream", exc_exec([[bdelete | call chansend(id, 'test')]])) eq("Vim(call):Can't send data to closed stream", pcall_err(command, [[bdelete | call chansend(id, 'test')]]))
-- process term_delayed_free and free_channel_event -- channel has been freed after one main loop iteration
poke_eventloop() eq("Vim(call):E900: Invalid channel id", pcall_err(command, [[call chansend(id, 'test')]]))
-- channel has been freed
eq("Vim(call):E900: Invalid channel id", exc_exec([[call chansend(id, 'test')]]))
end) end)
end) end)