@@ -294,6 +294,72 @@ endfunc
294294
295295" """"""""
296296
297+ let s: ch_reply = ' '
298+ func s: ChHandler (chan, msg)
299+ unlet s: ch_reply
300+ let s: ch_reply = a: msg
301+ endfunc
302+
303+ let s: zero_reply = ' '
304+ func s: OneHandler (chan, msg)
305+ unlet s: zero_reply
306+ let s: zero_reply = a: msg
307+ endfunc
308+
309+ func s: channel_zero (port)
310+ let handle = ch_open (' localhost:' . a: port , s: chopt )
311+ if ch_status (handle) == " fail"
312+ call assert_false (1 , " Can't open channel" )
313+ return
314+ endif
315+
316+ " Check that eval works.
317+ call assert_equal (' got it' , ch_evalexpr (handle, ' hello!' ))
318+
319+ " Check that eval works if a zero id message is sent back.
320+ let s: ch_reply = ' '
321+ call assert_equal (' sent zero' , ch_evalexpr (handle, ' send zero' ))
322+ sleep 10 m
323+ if s: has_handler
324+ call assert_equal (' zero index' , s: ch_reply )
325+ else
326+ call assert_equal (' ' , s: ch_reply )
327+ endif
328+
329+ " Check that handler works if a zero id message is sent back.
330+ let s: ch_reply = ' '
331+ let s: zero_reply = ' '
332+ call ch_sendexpr (handle, ' send zero' , {' callback' : ' s:OneHandler' })
333+ " Somehow the second message takes a bit of time.
334+ for i in range (50 )
335+ if s: zero_reply == ' sent zero'
336+ break
337+ endif
338+ sleep 10 m
339+ endfor
340+ if s: has_handler
341+ call assert_equal (' zero index' , s: ch_reply )
342+ else
343+ call assert_equal (' ' , s: ch_reply )
344+ endif
345+ call assert_equal (' sent zero' , s: zero_reply )
346+ endfunc
347+
348+ func Test_zero_reply ()
349+ call ch_log (' Test_zero_reply()' )
350+ " Run with channel handler
351+ let s: has_handler = 1
352+ let s: chopt .callback = ' s:ChHandler'
353+ call s: run_server (' s:channel_zero' )
354+ unlet s: chopt .callback
355+
356+ " Run without channel handler
357+ let s: has_handler = 0
358+ call s: run_server (' s:channel_zero' )
359+ endfunc
360+
361+ " """"""""
362+
297363let s: reply1 = " "
298364func s: HandleRaw1 (chan, msg)
299365 unlet s: reply1
0 commit comments