From 63a98fca552b1f7197dd2a37764a57604e3746e8 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 7 Nov 2014 11:01:59 -0300 Subject: [PATCH] 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. --- test/functional/helpers.lua | 10 ++++++++-- 1 file 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