1
0
forked from aniani/vim

patch 8.0.0492: a failing client-server request can make Vim hang

Problem:    A failing client-server request can make Vim hang.
Solution:   Add a timeout argument to functions that wait.
This commit is contained in:
Bram Moolenaar
2017-03-19 21:20:53 +01:00
parent bfd830d3e2
commit 81b9d0bd5c
10 changed files with 84 additions and 76 deletions

View File

@@ -6,22 +6,12 @@ endif
source shared.vim
let s:where = 0
func Abort(id)
call assert_report('Test timed out at ' . s:where)
call FinishTesting()
endfunc
func Test_client_server()
let cmd = GetVimCommand()
if cmd == ''
return
endif
" Some of these commands may hang when failing.
call timer_start(10000, 'Abort')
let s:where = 1
let name = 'XVIMTEST'
let cmd .= ' --servername ' . name
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
@@ -30,62 +20,53 @@ func Test_client_server()
call assert_report('Cannot run the Vim server')
return
endif
let s:where = 2
" Takes a short while for the server to be active.
call WaitFor('serverlist() =~ "' . name . '"')
call assert_match(name, serverlist())
let s:where = 3
call remote_foreground(name)
let s:where = 4
call remote_send(name, ":let testvar = 'yes'\<CR>")
let s:where = 5
call WaitFor('remote_expr("' . name . '", "testvar") == "yes"')
let s:where = 6
call assert_equal('yes', remote_expr(name, "testvar"))
let s:where = 7
call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "yes"')
call assert_equal('yes', remote_expr(name, "testvar", "", 2))
if has('unix') && has('gui') && !has('gui_running')
" Running in a terminal and the GUI is avaiable: Tell the server to open
" the GUI and check that the remote command still works.
" Need to wait for the GUI to start up, otherwise the send hangs in trying
" to send to the terminal window.
call remote_send(name, ":gui -f\<CR>")
let s:where = 8
sleep 500m
if has('gui_athena') || has('gui_motif')
" For those GUIs, ignore the 'failed to create input context' error.
call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
else
call remote_send(name, ":gui -f\<CR>")
endif
" Wait for the server to be up and answering requests.
call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""')
call remote_send(name, ":let testvar = 'maybe'\<CR>")
let s:where = 9
call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"')
let s:where = 10
call assert_equal('maybe', remote_expr(name, "testvar"))
let s:where = 11
call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"')
call assert_equal('maybe', remote_expr(name, "testvar", "", 2))
endif
call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
let s:where = 12
" Expression evaluated locally.
if v:servername == ''
call remote_startserver('MYSELF')
let s:where = 13
call assert_equal('MYSELF', v:servername)
" May get MYSELF1 when running the test again.
call assert_match('MYSELF', v:servername)
endif
let g:testvar = 'myself'
call assert_equal('myself', remote_expr(v:servername, 'testvar'))
let s:where = 14
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
let s:where = 15
call assert_equal('got it', remote_read(g:myserverid))
let s:where = 16
call assert_equal('got it', remote_read(g:myserverid, 2))
call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
let s:where = 151
let peek_result = 'nothing'
let r = remote_peek(g:myserverid, 'peek_result')
let s:where = 161
" unpredictable whether the result is already avaialble.
if r > 0
call assert_equal('another', peek_result)
@@ -96,16 +77,11 @@ func Test_client_server()
endif
let g:peek_result = 'empty'
call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0')
let s:where = 171
call assert_equal('another', g:peek_result)
let s:where = 181
call assert_equal('another', remote_read(g:myserverid))
let s:where = 191
call assert_equal('another', remote_read(g:myserverid, 2))
call remote_send(name, ":qa!\<CR>")
let s:where = 17
call WaitFor('job_status(g:job) == "dead"')
let s:where = 18
if job_status(g:job) != 'dead'
call assert_report('Server did not exit')
call job_stop(g:job, 'kill')