patch 7.4.1249
Problem: Crash when the process a channel is connected to exits.
Solution: Use the file descriptor properly. Add a test. (Damien)
Also add a test for eval().
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 9d4c778..d128990 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -18,25 +18,14 @@
endif
func s:start_server()
+ " The Python program writes the port number in Xportnr.
+ call delete("Xportnr")
+
if has('win32')
silent !start cmd /c start "test_channel" py test_channel.py
else
silent !python test_channel.py&
endif
-endfunc
-
-func s:kill_server()
- if has('win32')
- call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
- else
- call system("pkill --full test_channel.py")
- endif
-endfunc
-
-func Test_communicate()
- call delete("Xportnr")
- " The Python program writes the port number in Xportnr.
- call s:start_server()
" Wait for up to 2 seconds for the port number to be there.
let cnt = 20
@@ -57,10 +46,28 @@
if len(l) == 0
" Can't make the connection, give up.
call s:kill_server()
- return
+ call assert_false(1, "Can't start test_channel.py")
+ return -1
endif
let port = l[0]
+
let handle = ch_open('localhost:' . port, 'json')
+ return handle
+endfunc
+
+func s:kill_server()
+ if has('win32')
+ call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
+ else
+ call system("pkill --full test_channel.py")
+ endif
+endfunc
+
+func Test_communicate()
+ let handle = s:start_server()
+ if handle < 0
+ return
+ endif
" Simple string request and reply.
call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
@@ -73,8 +80,29 @@
call assert_equal('added1', getline(line('$') - 1))
call assert_equal('added2', getline('$'))
+ " Send an eval request that works.
+ call assert_equal('ok', ch_sendexpr(handle, 'eval-works'))
+ call assert_equal([-1, 'foo123'], ch_sendexpr(handle, 'eval-result'))
+
+ " Send an eval request that fails.
+ call assert_equal('ok', ch_sendexpr(handle, 'eval-fails'))
+ call assert_equal([-2, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
+
" 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 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