aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-03-18 18:36:02 +0100
committerGitHub <noreply@github.com>2018-03-18 18:36:02 +0100
commit4e02f1ab871f30d80250537877924d522497493b (patch)
tree0a054babaa09767e5c31d7f485a7901e29188b35 /test
parent0848add4885adaa61218cc5394dc23d92c5812df (diff)
parentae409b5042abdbec67305a063cf921ddffcce0c8 (diff)
downloadrneovim-4e02f1ab871f30d80250537877924d522497493b.tar.gz
rneovim-4e02f1ab871f30d80250537877924d522497493b.tar.bz2
rneovim-4e02f1ab871f30d80250537877924d522497493b.zip
Merge #8107 'jobs: separate process-group'
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/proc_spec.lua81
-rw-r--r--test/functional/autocmd/termclose_spec.lua25
-rw-r--r--test/functional/core/job_spec.lua40
3 files changed, 136 insertions, 10 deletions
diff --git a/test/functional/api/proc_spec.lua b/test/functional/api/proc_spec.lua
new file mode 100644
index 0000000000..d99c26b6c2
--- /dev/null
+++ b/test/functional/api/proc_spec.lua
@@ -0,0 +1,81 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local eq = helpers.eq
+local funcs = helpers.funcs
+local iswin = helpers.iswin
+local nvim_argv = helpers.nvim_argv
+local ok = helpers.ok
+local request = helpers.request
+local retry = helpers.retry
+local NIL = helpers.NIL
+
+describe('api', function()
+ before_each(clear)
+
+ describe('nvim_get_proc_children', function()
+ it('returns child process ids', function()
+ local this_pid = funcs.getpid()
+
+ local job1 = funcs.jobstart(nvim_argv)
+ retry(nil, nil, function()
+ eq(1, #request('nvim_get_proc_children', this_pid))
+ end)
+
+ local job2 = funcs.jobstart(nvim_argv)
+ retry(nil, nil, function()
+ eq(2, #request('nvim_get_proc_children', this_pid))
+ end)
+
+ funcs.jobstop(job1)
+ retry(nil, nil, function()
+ eq(1, #request('nvim_get_proc_children', this_pid))
+ end)
+
+ funcs.jobstop(job2)
+ retry(nil, nil, function()
+ eq(0, #request('nvim_get_proc_children', this_pid))
+ end)
+ end)
+
+ it('validates input', function()
+ local status, rv = pcall(request, "nvim_get_proc_children", -1)
+ eq(false, status)
+ eq("Invalid pid: -1", string.match(rv, "Invalid.*"))
+
+ status, rv = pcall(request, "nvim_get_proc_children", 0)
+ eq(false, status)
+ eq("Invalid pid: 0", string.match(rv, "Invalid.*"))
+
+ -- Assume PID 99999 does not exist.
+ status, rv = pcall(request, "nvim_get_proc_children", 99999)
+ eq(true, status)
+ eq({}, rv)
+ end)
+ end)
+
+ describe('nvim_get_proc', function()
+ it('returns process info', function()
+ local pid = funcs.getpid()
+ local pinfo = request('nvim_get_proc', pid)
+ eq((iswin() and 'nvim.exe' or 'nvim'), pinfo.name)
+ ok(pinfo.pid == pid)
+ ok(type(pinfo.ppid) == 'number' and pinfo.ppid ~= pid)
+ end)
+
+ it('validates input', function()
+ local status, rv = pcall(request, "nvim_get_proc", -1)
+ eq(false, status)
+ eq("Invalid pid: -1", string.match(rv, "Invalid.*"))
+
+ status, rv = pcall(request, "nvim_get_proc", 0)
+ eq(false, status)
+ eq("Invalid pid: 0", string.match(rv, "Invalid.*"))
+
+ -- Assume PID 99999 does not exist.
+ status, rv = pcall(request, "nvim_get_proc", 99999)
+ eq(true, status)
+ eq(NIL, rv)
+ end)
+ end)
+end)
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
index 9918cbe4fa..0804579a4f 100644
--- a/test/functional/autocmd/termclose_spec.lua
+++ b/test/functional/autocmd/termclose_spec.lua
@@ -1,3 +1,4 @@
+local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each)
local clear, command, nvim, nvim_dir =
@@ -39,13 +40,15 @@ describe('TermClose event', function()
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end)
- local start = os.time()
+ luv.update_time()
+ local start = luv.now()
command('call jobstop(g:test_job)')
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
- local duration = os.time() - start
- -- nvim starts sending SIGTERM after KILL_TIMEOUT_MS
- ok(duration >= 2)
- ok(duration <= 4) -- <= 2 + delta because of slow CI
+ luv.update_time()
+ local duration = luv.now() - start
+ -- Nvim begins SIGTERM after KILL_TIMEOUT_MS.
+ ok(duration >= 2000)
+ ok(duration <= 4000) -- Epsilon for slow CI
end)
it('kills pty job trapping SIGHUP and SIGTERM', function()
@@ -58,13 +61,15 @@ describe('TermClose event', function()
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_started", 0)')) end)
- local start = os.time()
+ luv.update_time()
+ local start = luv.now()
command('call jobstop(g:test_job)')
retry(nil, nil, function() eq(1, eval('get(g:, "test_job_exited", 0)')) end)
- local duration = os.time() - start
- -- nvim starts sending kill after 2*KILL_TIMEOUT_MS
- ok(duration >= 4)
- ok(duration <= 7) -- <= 4 + delta because of slow CI
+ luv.update_time()
+ local duration = luv.now() - start
+ -- Nvim begins SIGKILL after (2 * KILL_TIMEOUT_MS).
+ ok(duration >= 4000)
+ ok(duration <= 7000) -- Epsilon for slow CI
end)
it('reports the correct <abuf>', function()
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index c5326aedfe..6d4cadbdc8 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -6,6 +6,10 @@ local clear, eq, eval, exc_exec, feed_command, feed, insert, neq, next_msg, nvim
helpers.nvim_dir, helpers.ok, helpers.source,
helpers.write_file, helpers.mkdir, helpers.rmdir
local command = helpers.command
+local funcs = helpers.funcs
+local retry = helpers.retry
+local meths = helpers.meths
+local NIL = helpers.NIL
local wait = helpers.wait
local iswin = helpers.iswin
local get_pathsep = helpers.get_pathsep
@@ -636,6 +640,42 @@ describe('jobs', function()
ok(string.find(err, "E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set") ~= nil)
end)
+ it('jobstop() kills entire process tree #6530', function()
+ command('set shell& shellcmdflag& shellquote& shellpipe& shellredir& shellxquote&')
+
+ -- XXX: Using `nvim` isn't a good test, it reaps its children on exit.
+ -- local c = 'call jobstart([v:progpath, "-u", "NONE", "-i", "NONE", "--headless"])'
+ -- local j = eval("jobstart([v:progpath, '-u', 'NONE', '-i', 'NONE', '--headless', '-c', '"
+ -- ..c.."', '-c', '"..c.."'])")
+
+ -- Create child with several descendants.
+ local j = (iswin()
+ and eval([=[jobstart('start /b cmd /c "ping 127.0.0.1 -n 1 -w 30000 > NUL"]=]
+ ..[=[ & start /b cmd /c "ping 127.0.0.1 -n 1 -w 40000 > NUL"]=]
+ ..[=[ & start /b cmd /c "ping 127.0.0.1 -n 1 -w 50000 > NUL"')]=])
+ or eval("jobstart('sleep 30 | sleep 30 | sleep 30')"))
+ local ppid = funcs.jobpid(j)
+ local children
+ retry(nil, nil, function()
+ children = meths.get_proc_children(ppid)
+ eq(3, #children)
+ end)
+ -- Assert that nvim_get_proc() sees the children.
+ for _, child_pid in ipairs(children) do
+ local info = meths.get_proc(child_pid)
+ -- eq((iswin() and 'nvim.exe' or 'nvim'), info.name)
+ eq(ppid, info.ppid)
+ end
+ -- Kill the root of the tree.
+ funcs.jobstop(j)
+ -- Assert that the children were killed.
+ retry(nil, nil, function()
+ for _, child_pid in ipairs(children) do
+ eq(NIL, meths.get_proc(child_pid))
+ end
+ end)
+ end)
+
describe('running tty-test program', function()
if helpers.pending_win32(pending) then return end
local function next_chunk()