From 7707344ddec9069b495b2a5ed41f2104466fc88b Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 13 Feb 2016 23:23:53 +0100 Subject: patch 7.4.1315 Problem: Using a channel handle does not allow for freeing it when unused. Solution: Add the Channel variable type. --- src/testdir/test_channel.py | 8 +------- src/testdir/test_channel.vim | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src/testdir') diff --git a/src/testdir/test_channel.py b/src/testdir/test_channel.py index 311fbc07c..ce6d5c16d 100644 --- a/src/testdir/test_channel.py +++ b/src/testdir/test_channel.py @@ -1,13 +1,7 @@ #!/usr/bin/python # # Server that will accept connections from a Vim channel. -# Run this server and then in Vim you can open the channel: -# :let handle = ch_open('localhost:8765', 'json') -# -# Then Vim can send requests to the server: -# :let response = ch_sendexpr(handle, 'hello!') -# -# See ":help channel-demo" in Vim. +# Used by test_channel.vim. # # This requires Python 2.6 or later. diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index f0a149d19..e894c09cc 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -83,7 +83,6 @@ func s:kill_server() endif endfunc -let s:responseHandle = -1 let s:responseMsg = '' func s:RequestHandler(handle, msg) let s:responseHandle = a:handle @@ -92,7 +91,7 @@ endfunc func s:communicate(port) let handle = ch_open('localhost:' . a:port, s:chopt) - if handle < 0 + if ch_status(handle) == "fail" call assert_false(1, "Can't open channel") return endif @@ -115,14 +114,22 @@ func s:communicate(port) " Send a request with a specific handler. call ch_sendexpr(handle, 'hello!', 's:RequestHandler') sleep 10m - call assert_equal(handle, s:responseHandle) + if !exists('s:responseHandle') + call assert_false(1, 's:responseHandle was not set') + else + call assert_equal(handle, s:responseHandle) + endif call assert_equal('got it', s:responseMsg) - let s:responseHandle = -1 + unlet s:responseHandle let s:responseMsg = '' call ch_sendexpr(handle, 'hello!', function('s:RequestHandler')) sleep 10m - call assert_equal(handle, s:responseHandle) + if !exists('s:responseHandle') + call assert_false(1, 's:responseHandle was not set') + else + call assert_equal(handle, s:responseHandle) + endif call assert_equal('got it', s:responseMsg) " Send an eval request that works. @@ -169,7 +176,7 @@ endfunc " Test that we can open two channels. func s:two_channels(port) let handle = ch_open('localhost:' . a:port, s:chopt) - if handle < 0 + if ch_status(handle) == "fail" call assert_false(1, "Can't open channel") return endif @@ -177,7 +184,7 @@ func s:two_channels(port) call assert_equal('got it', ch_sendexpr(handle, 'hello!')) let newhandle = ch_open('localhost:' . a:port, s:chopt) - if newhandle < 0 + if ch_status(newhandle) == "fail" call assert_false(1, "Can't open second channel") return endif @@ -197,7 +204,7 @@ 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 + if ch_status(handle) == "fail" call assert_false(1, "Can't open channel") return endif @@ -219,7 +226,7 @@ endfunc func s:channel_handler(port) let handle = ch_open('localhost:' . a:port, s:chopt) - if handle < 0 + if ch_status(handle) == "fail" call assert_false(1, "Can't open channel") return endif @@ -247,7 +254,7 @@ endfunc func Test_connect_waittime() let start = reltime() let handle = ch_open('localhost:9876', s:chopt) - if handle >= 0 + if ch_status(handle) == "fail" " Oops, port does exists. call ch_close(handle) else @@ -257,7 +264,7 @@ func Test_connect_waittime() let start = reltime() let handle = ch_open('localhost:9867', {'waittime': 2000}) - if handle >= 0 + if ch_status(handle) != "fail" " Oops, port does exists. call ch_close(handle) else -- cgit v1.2.1