Patch 7.4.1298
Problem: When the channel test fails in an unexpected way the server keeps
running.
Solution: Use try/catch. (Ozaki Kiichi)
Files: src/testdir/test_channel.vim
*** ../vim-7.4.1297/src/testdir/test_channel.vim 2016-02-09
23:33:19.131446251 +0100
--- src/testdir/test_channel.vim 2016-02-10 20:29:40.592746125 +0100
***************
*** 19,73 ****
finish
endif
else
finish
endif
- let s:port = -1
let s:chopt = has('macunix') ? {'waittime' : 1} : {}
! func s:start_server()
" The Python program writes the port number in Xportnr.
call delete("Xportnr")
! if has('job')
! let s:job = job_start("python test_channel.py")
! elseif has('win32')
! silent !start cmd /c start "test_channel" py test_channel.py
! else
! silent !python test_channel.py&
! endif
! " Wait for up to 2 seconds for the port number to be there.
! let cnt = 20
! let l = []
! while cnt > 0
! try
! let l = readfile("Xportnr")
! catch
! endtry
! if len(l) >= 1
! break
endif
! sleep 100m
! let cnt -= 1
! endwhile
! call delete("Xportnr")
! if len(l) == 0
! " Can't make the connection, give up.
call s:kill_server()
! call assert_false(1, "Can't start test_channel.py")
! return -1
! endif
! let s:port = l[0]
!
! let handle = ch_open('localhost:' . s:port, s:chopt)
! return handle
endfunc
func s:kill_server()
if has('job')
! call job_stop(s:job)
elseif has('win32')
call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
else
--- 19,81 ----
finish
endif
else
+ " Can't run this test.
finish
endif
let s:chopt = has('macunix') ? {'waittime' : 1} : {}
! " 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.
call delete("Xportnr")
! try
! if has('job')
! let s:job = job_start("python test_channel.py")
! elseif has('win32')
! silent !start cmd /c start "test_channel" py test_channel.py
! else
! silent !python test_channel.py&
! endif
! " Wait for up to 2 seconds for the port number to be there.
! let cnt = 20
! let l = []
! while cnt > 0
! try
! let l = readfile("Xportnr")
! catch
! endtry
! if len(l) >= 1
! break
! endif
! sleep 100m
! let cnt -= 1
! endwhile
! call delete("Xportnr")
!
! if len(l) == 0
! " Can't make the connection, give up.
! call assert_false(1, "Can't start test_channel.py")
! return -1
endif
! let port = l[0]
! call call(function(a:testfunc), [port])
! catch
! call assert_false(1, "Caught exception: " . v:exception)
! finally
call s:kill_server()
! endtry
endfunc
func s:kill_server()
if has('job')
! if exists('s:job')
! call job_stop(s:job)
! unlet s:job
! endif
elseif has('win32')
call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
else
***************
*** 82,90 ****
let s:responseMsg = a:msg
endfunc
! func Test_communicate()
! let handle = s:start_server()
if handle < 0
return
endif
--- 90,99 ----
let s:responseMsg = a:msg
endfunc
! func s:communicate(port)
! let handle = ch_open('localhost:' . a:port, s:chopt)
if handle < 0
+ call assert_false(1, "Can't open channel")
return
endif
***************
*** 144,182 ****
" make the server quit, can't check if this works, should not hang.
call ch_sendexpr(handle, '!quit!', 0)
! call s:kill_server()
endfunc
" Test that we can open two channels.
! func Test_two_channels()
! let handle = s:start_server()
if handle < 0
return
endif
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
! let newhandle = ch_open('localhost:' . s:port, s:chopt)
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
call ch_close(handle)
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
! call s:kill_server()
endfunc
" Test that a server crash is handled gracefully.
! func Test_server_crash()
! let handle = s:start_server()
if handle < 0
return
endif
call ch_sendexpr(handle, '!crash!')
- " kill the server in case if failed to crash
sleep 10m
! call s:kill_server()
endfunc
" Test that trying to connect to a non-existing port fails quickly.
--- 153,207 ----
" make the server quit, can't check if this works, should not hang.
call ch_sendexpr(handle, '!quit!', 0)
+ endfunc
! func Test_communicate()
! call s:run_server('s:communicate')
endfunc
" Test that we can open two channels.
! func s:two_channels(port)
! let handle = ch_open('localhost:' . a:port)
if handle < 0
+ call assert_false(1, "Can't open channel")
return
endif
+
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
! 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(handle, 'hello!'))
call ch_close(handle)
call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
! call ch_close(newhandle)
! endfunc
!
! func Test_two_channels()
! call s:run_server('s:two_channels')
endfunc
" Test that a server crash is handled gracefully.
! func s:server_crash(port)
! let handle = ch_open('localhost:' . a:port, s:chopt)
if handle < 0
+ call assert_false(1, "Can't open channel")
return
endif
+
call ch_sendexpr(handle, '!crash!')
sleep 10m
! endfunc
!
! func Test_server_crash()
! call s:run_server('s:server_crash')
endfunc
" Test that trying to connect to a non-existing port fails quickly.
***************
*** 198,203 ****
--- 223,229 ----
call ch_close(handle)
else
" Failed connection doesn't wait the full time on Unix.
+ " TODO: why is MS-Windows different?
let elapsed = reltime(start)
call assert_true(reltimefloat(elapsed) < (has('unix') ? 1.0 : 3.0))
endif
*** ../vim-7.4.1297/src/version.c 2016-02-09 23:33:19.131446251 +0100
--- src/version.c 2016-02-10 20:32:08.691199529 +0100
***************
*** 749,750 ****
--- 749,752 ----
{ /* Add new patch number below this line */
+ /**/
+ 1298,
/**/
--
hundred-and-one symptoms of being an internet addict:
216. Your pet rock leaves home.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.