aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-06 04:36:46 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-06 04:36:46 -0300
commit4cc26fba249361cccd791a76fc35c46d851096a5 (patch)
tree42bdfa20a8247d278a4a82039a98a1b8e01a67c9 /test
parent3972715ce791466c1ea3c873f78e95e13eba6e58 (diff)
parentd83868fe9071af1b4866594eac12f7aa0fa71b53 (diff)
downloadrneovim-4cc26fba249361cccd791a76fc35c46d851096a5.tar.gz
rneovim-4cc26fba249361cccd791a76fc35c46d851096a5.tar.bz2
rneovim-4cc26fba249361cccd791a76fc35c46d851096a5.zip
Merge PR #1398 'Tests and msgpack rpc improvements'
Diffstat (limited to 'test')
-rw-r--r--test/functional/api/server_requests_spec.lua56
-rw-r--r--test/functional/legacy/options_spec.lua16
2 files changed, 59 insertions, 13 deletions
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index b6f56a868c..916bdfd9f0 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -2,8 +2,10 @@
-- `rpcnotify`, to evaluate `rpcrequest` calls we need the client event loop to
-- be running.
local helpers = require('test.functional.helpers')
-local clear, nvim, eval, eq, run, stop = helpers.clear, helpers.nvim,
- helpers.eval, helpers.eq, helpers.run, helpers.stop
+local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
+local eq, run, stop = helpers.eq, helpers.run, helpers.stop
+local restart = helpers.restart
+
describe('server -> client', function()
@@ -13,6 +15,7 @@ describe('server -> client', function()
clear()
cid = nvim('get_api_info')[1]
end)
+ teardown(restart)
describe('simple call', function()
it('works', function()
@@ -65,4 +68,53 @@ describe('server -> client', function()
run(on_request, nil, on_setup)
end)
end)
+
+ describe('requests and notifications interleaved', function()
+ -- This tests that the following scenario won't happen:
+ --
+ -- server->client [request ] (1)
+ -- client->server [request ] (2) triggered by (1)
+ -- server->client [notification] (3) triggered by (2)
+ -- server->client [response ] (4) response to (2)
+ -- client->server [request ] (4) triggered by (3)
+ -- server->client [request ] (5) triggered by (4)
+ -- client->server [response ] (6) response to (1)
+ --
+ -- If the above scenario ever happens, the client connection will be closed
+ -- because (6) is returned after request (5) is sent, and nvim
+ -- only deals with one server->client request at a time. (In other words,
+ -- the client cannot send a response to a request that is not at the top
+ -- of nvim's request stack).
+ --
+ -- But above scenario shoudn't happen by the way notifications are dealt in
+ -- Nvim: they are only sent after there are no pending server->client
+ -- request(the request stack fully unwinds). So (3) is only sent after the
+ -- client returns (6).
+ it('works', function()
+ local expected = 300
+ local notified = 0
+ local function on_setup()
+ eq('notified!', eval('rpcrequest('..cid..', "notify")'))
+ end
+
+ local function on_request(method, args)
+ eq('notify', method)
+ eq(1, eval('rpcnotify('..cid..', "notification")'))
+ return 'notified!'
+ end
+
+ local function on_notification(method, args)
+ eq('notification', method)
+ if notified == expected then
+ stop()
+ return
+ end
+ notified = notified + 1
+ eq('notified', eval('rpcrequest('..cid..', "notify")'))
+ end
+
+ run(on_request, on_notification, on_setup)
+ eq(expected, notified)
+ end)
+ end)
end)
diff --git a/test/functional/legacy/options_spec.lua b/test/functional/legacy/options_spec.lua
index fcc39434ff..983d168609 100644
--- a/test/functional/legacy/options_spec.lua
+++ b/test/functional/legacy/options_spec.lua
@@ -1,20 +1,14 @@
--- Test for ":options".
+-- Test if ":options" throws any exception. The options window seems to mess
+-- other tests, so restart nvim in the teardown hook
local helpers = require('test.functional.helpers')
-local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
-local execute, expect = helpers.execute, helpers.expect
+local restart, command, clear = helpers.restart, helpers.command, helpers.clear
describe('options', function()
setup(clear)
+ teardown(restart)
it('is working', function()
- insert('result')
-
- execute("let caught = 'ok'")
- execute('try', 'options', 'catch', 'let caught = v:throwpoint . "\n" . v:exception', 'endtry')
- execute('buf 1')
- execute('$put =caught')
-
- expect("result\nok")
+ command('options')
end)
end)