mirror of
https://github.com/vim/vim.git
synced 2025-10-06 05:44:14 -04:00
patch 7.4.1298
Problem: When the channel test fails in an unexpected way the server keeps running. Solution: Use try/catch. (Ozaki Kiichi)
This commit is contained in:
@@ -19,16 +19,18 @@ elseif has('win32')
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
|
" Can't run this test.
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:port = -1
|
|
||||||
let s:chopt = has('macunix') ? {'waittime' : 1} : {}
|
let s:chopt = has('macunix') ? {'waittime' : 1} : {}
|
||||||
|
|
||||||
func s:start_server()
|
" Run "testfunc" after sarting the server and stop the server afterwards.
|
||||||
|
func s:run_server(testfunc)
|
||||||
" The Python program writes the port number in Xportnr.
|
" The Python program writes the port number in Xportnr.
|
||||||
call delete("Xportnr")
|
call delete("Xportnr")
|
||||||
|
|
||||||
|
try
|
||||||
if has('job')
|
if has('job')
|
||||||
let s:job = job_start("python test_channel.py")
|
let s:job = job_start("python test_channel.py")
|
||||||
elseif has('win32')
|
elseif has('win32')
|
||||||
@@ -55,19 +57,25 @@ func s:start_server()
|
|||||||
|
|
||||||
if len(l) == 0
|
if len(l) == 0
|
||||||
" Can't make the connection, give up.
|
" Can't make the connection, give up.
|
||||||
call s:kill_server()
|
|
||||||
call assert_false(1, "Can't start test_channel.py")
|
call assert_false(1, "Can't start test_channel.py")
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
let s:port = l[0]
|
let port = l[0]
|
||||||
|
|
||||||
let handle = ch_open('localhost:' . s:port, s:chopt)
|
call call(function(a:testfunc), [port])
|
||||||
return handle
|
catch
|
||||||
|
call assert_false(1, "Caught exception: " . v:exception)
|
||||||
|
finally
|
||||||
|
call s:kill_server()
|
||||||
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func s:kill_server()
|
func s:kill_server()
|
||||||
if has('job')
|
if has('job')
|
||||||
|
if exists('s:job')
|
||||||
call job_stop(s:job)
|
call job_stop(s:job)
|
||||||
|
unlet s:job
|
||||||
|
endif
|
||||||
elseif has('win32')
|
elseif has('win32')
|
||||||
call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
|
call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
|
||||||
else
|
else
|
||||||
@@ -82,9 +90,10 @@ func s:RequestHandler(handle, msg)
|
|||||||
let s:responseMsg = a:msg
|
let s:responseMsg = a:msg
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_communicate()
|
func s:communicate(port)
|
||||||
let handle = s:start_server()
|
let handle = ch_open('localhost:' . a:port, s:chopt)
|
||||||
if handle < 0
|
if handle < 0
|
||||||
|
call assert_false(1, "Can't open channel")
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -144,39 +153,55 @@ func Test_communicate()
|
|||||||
|
|
||||||
" make the server quit, can't check if this works, should not hang.
|
" make the server quit, can't check if this works, should not hang.
|
||||||
call ch_sendexpr(handle, '!quit!', 0)
|
call ch_sendexpr(handle, '!quit!', 0)
|
||||||
|
endfunc
|
||||||
|
|
||||||
call s:kill_server()
|
func Test_communicate()
|
||||||
|
call s:run_server('s:communicate')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test that we can open two channels.
|
" Test that we can open two channels.
|
||||||
func Test_two_channels()
|
func s:two_channels(port)
|
||||||
let handle = s:start_server()
|
let handle = ch_open('localhost:' . a:port)
|
||||||
if handle < 0
|
if handle < 0
|
||||||
|
call assert_false(1, "Can't open channel")
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
|
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
|
||||||
|
|
||||||
let newhandle = ch_open('localhost:' . s:port, s:chopt)
|
let newhandle = ch_open('localhost:' . a:port, s:chopt)
|
||||||
|
if newhandle < 0
|
||||||
|
call assert_false(1, "Can't open second channel")
|
||||||
|
return
|
||||||
|
endif
|
||||||
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
|
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
|
||||||
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
|
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
|
||||||
|
|
||||||
call ch_close(handle)
|
call ch_close(handle)
|
||||||
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
|
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
|
||||||
|
|
||||||
call s:kill_server()
|
call ch_close(newhandle)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_two_channels()
|
||||||
|
call s:run_server('s:two_channels')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test that a server crash is handled gracefully.
|
" Test that a server crash is handled gracefully.
|
||||||
func Test_server_crash()
|
func s:server_crash(port)
|
||||||
let handle = s:start_server()
|
let handle = ch_open('localhost:' . a:port, s:chopt)
|
||||||
if handle < 0
|
if handle < 0
|
||||||
|
call assert_false(1, "Can't open channel")
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call ch_sendexpr(handle, '!crash!')
|
call ch_sendexpr(handle, '!crash!')
|
||||||
|
|
||||||
" kill the server in case if failed to crash
|
|
||||||
sleep 10m
|
sleep 10m
|
||||||
call s:kill_server()
|
endfunc
|
||||||
|
|
||||||
|
func Test_server_crash()
|
||||||
|
call s:run_server('s:server_crash')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test that trying to connect to a non-existing port fails quickly.
|
" Test that trying to connect to a non-existing port fails quickly.
|
||||||
@@ -198,6 +223,7 @@ func Test_connect_waittime()
|
|||||||
call ch_close(handle)
|
call ch_close(handle)
|
||||||
else
|
else
|
||||||
" Failed connection doesn't wait the full time on Unix.
|
" Failed connection doesn't wait the full time on Unix.
|
||||||
|
" TODO: why is MS-Windows different?
|
||||||
let elapsed = reltime(start)
|
let elapsed = reltime(start)
|
||||||
call assert_true(reltimefloat(elapsed) < (has('unix') ? 1.0 : 3.0))
|
call assert_true(reltimefloat(elapsed) < (has('unix') ? 1.0 : 3.0))
|
||||||
endif
|
endif
|
||||||
|
@@ -747,6 +747,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1298,
|
||||||
/**/
|
/**/
|
||||||
1297,
|
1297,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user