From 8921d56053bb3702226c03f13232b45d5f2c27a4 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 21 Mar 2024 10:08:31 +0100 Subject: fix(rpc): do not crash when no input is consumed fixes #23781 Co-authored-by: glacambre --- test/functional/api/server_requests_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 298dbac217..562eeae951 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -363,6 +363,24 @@ describe('server -> client', function() server:close() client:close() end) + + it('via stdio, with many small flushes does not crash #23781', function() + source([[ + let chan = jobstart([v:progpath, '--embed', '--headless', '-n', '-u', 'NONE', '-i', 'NONE'], { 'rpc':v:false }) + call chansend(chan, 0Z94) + sleep 50m + call chansend(chan, 0Z00) + call chansend(chan, 0Z01) + call chansend(chan, 0ZAC) + call chansend(chan, 0Z6E76696D5F636F6D6D616E64) + call chansend(chan, 0Z91) + call chansend(chan, 0ZA5) + call chansend(chan, 0Z71616C6C21) + let g:statuses = jobwait([chan]) + ]]) + eq(eval('g:statuses'), { 0 }) + assert_alive() + end) end) describe('connecting to its own pipe address', function() -- cgit From 7035125b2b26aa68fcfb7cda39377ac79926a0f9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 11:03:20 +0200 Subject: test: improve test conventions Work on https://github.com/neovim/neovim/issues/27004. --- test/functional/api/server_requests_spec.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 562eeae951..3a925dcbe2 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -1,17 +1,17 @@ -- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate -- `rpcrequest` calls we need the client event loop to be running. -local helpers = require('test.functional.helpers')(after_each) - -local clear, eval = helpers.clear, helpers.eval -local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop -local nvim_prog, command, fn = helpers.nvim_prog, helpers.command, helpers.fn -local source, next_msg = helpers.source, helpers.next_msg -local ok = helpers.ok -local api = helpers.api -local spawn, merge_args = helpers.spawn, helpers.merge_args -local set_session = helpers.set_session -local pcall_err = helpers.pcall_err -local assert_alive = helpers.assert_alive +local t = require('test.functional.testutil')(after_each) + +local clear, eval = t.clear, t.eval +local eq, neq, run, stop = t.eq, t.neq, t.run, t.stop +local nvim_prog, command, fn = t.nvim_prog, t.command, t.fn +local source, next_msg = t.source, t.next_msg +local ok = t.ok +local api = t.api +local spawn, merge_args = t.spawn, t.merge_args +local set_session = t.set_session +local pcall_err = t.pcall_err +local assert_alive = t.assert_alive describe('server -> client', function() local cid @@ -259,7 +259,7 @@ describe('server -> client', function() pcall(fn.jobstop, jobid) end) - if helpers.skip(helpers.is_os('win')) then + if t.skip(t.is_os('win')) then return end @@ -280,7 +280,7 @@ describe('server -> client', function() end) describe('connecting to another (peer) nvim', function() - local nvim_argv = merge_args(helpers.nvim_argv, { '--headless' }) + local nvim_argv = merge_args(t.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) -- cgit From 81fc27124b9e1b375e0ce9605ae69c3c2a2d9222 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 9 Apr 2024 12:26:16 +0100 Subject: refactor(test): inject after_each differently --- test/functional/api/server_requests_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 3a925dcbe2..5385b23ec1 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -1,6 +1,6 @@ -- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate -- `rpcrequest` calls we need the client event loop to be running. -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local clear, eval = t.clear, t.eval local eq, neq, run, stop = t.eq, t.neq, t.run, t.stop -- cgit From 052498ed42780a76daea589d063cd8947a894673 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 20 Apr 2024 17:44:13 +0200 Subject: test: improve test conventions Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004. --- test/functional/api/server_requests_spec.lua | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'test/functional/api/server_requests_spec.lua') diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua index 5385b23ec1..bdd340f6c6 100644 --- a/test/functional/api/server_requests_spec.lua +++ b/test/functional/api/server_requests_spec.lua @@ -1,17 +1,18 @@ -- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate -- `rpcrequest` calls we need the client event loop to be running. -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local clear, eval = t.clear, t.eval -local eq, neq, run, stop = t.eq, t.neq, t.run, t.stop -local nvim_prog, command, fn = t.nvim_prog, t.command, t.fn -local source, next_msg = t.source, t.next_msg +local clear, eval = n.clear, n.eval +local eq, neq, run, stop = t.eq, t.neq, n.run, n.stop +local nvim_prog, command, fn = n.nvim_prog, n.command, n.fn +local source, next_msg = n.source, n.next_msg local ok = t.ok -local api = t.api -local spawn, merge_args = t.spawn, t.merge_args -local set_session = t.set_session +local api = n.api +local spawn, merge_args = n.spawn, n.merge_args +local set_session = n.set_session local pcall_err = t.pcall_err -local assert_alive = t.assert_alive +local assert_alive = n.assert_alive describe('server -> client', function() local cid @@ -91,19 +92,19 @@ describe('server -> client', function() local function on_request(method, args) eq('rcall', method) - local n = unpack(args) * 2 - if n <= 16 then + local _n = unpack(args) * 2 + if _n <= 16 then local cmd - if n == 4 then - cmd = 'let g:result2 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' - elseif n == 8 then - cmd = 'let g:result3 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' - elseif n == 16 then - cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. n .. ')' + if _n == 4 then + cmd = 'let g:result2 = rpcrequest(' .. cid .. ', "rcall", ' .. _n .. ')' + elseif _n == 8 then + cmd = 'let g:result3 = rpcrequest(' .. cid .. ', "rcall", ' .. _n .. ')' + elseif _n == 16 then + cmd = 'let g:result4 = rpcrequest(' .. cid .. ', "rcall", ' .. _n .. ')' end command(cmd) end - return n + return _n end run(on_request, nil, on_setup) end) @@ -280,7 +281,7 @@ describe('server -> client', function() end) describe('connecting to another (peer) nvim', function() - local nvim_argv = merge_args(t.nvim_argv, { '--headless' }) + local nvim_argv = merge_args(n.nvim_argv, { '--headless' }) local function connect_test(server, mode, address) local serverpid = fn.getpid() local client = spawn(nvim_argv, false, nil, true) -- cgit