aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-11-07 11:01:59 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-10 18:46:09 -0300
commit63a98fca552b1f7197dd2a37764a57604e3746e8 (patch)
treeccb87b68ae25498f29f7e2e3cba85337e14f04e6 /test/functional/helpers.lua
parentb0cd397a43ae18942e12b1c76f838aac135b18cf (diff)
downloadrneovim-63a98fca552b1f7197dd2a37764a57604e3746e8.tar.gz
rneovim-63a98fca552b1f7197dd2a37764a57604e3746e8.tar.bz2
rneovim-63a98fca552b1f7197dd2a37764a57604e3746e8.zip
test: Fix nondeterminism in tests with notifications
Tests which spin the event loop and stop it in a notification handler have a chance of re-entering the event loop due to the `vim_eval` call in the `request()` helper(assuming the request call is what triggered the notification). Since this will cause an error to be thrown by the lua client, don't send the extra `vim_eval` request when the loop has been stopped.
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index bf6e3dd38a..6c3f5190c9 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -25,7 +25,7 @@ if os.getenv('VALGRIND') then
nvim_argv = valgrind_argv
end
-local session, loop_running, last_error
+local session, loop_running, loop_stopped, last_error
local function request(method, ...)
local status, rv = session:request(method, ...)
@@ -39,7 +39,11 @@ local function request(method, ...)
end
-- Make sure this will only return after all buffered characters have been
-- processed
- session:request('vim_eval', '1')
+ if not loop_stopped then
+ -- Except when the loop has been stopped by a notification triggered
+ -- by the initial request, for example.
+ session:request('vim_eval', '1')
+ end
return rv
end
@@ -71,6 +75,7 @@ local function run(request_cb, notification_cb, setup_cb)
call_and_stop_on_error(setup_cb)
end
+ loop_stopped = false
loop_running = true
session:run(on_request, on_notification, on_setup)
loop_running = false
@@ -82,6 +87,7 @@ local function run(request_cb, notification_cb, setup_cb)
end
local function stop()
+ loop_stopped = true
session:stop()
end