diff src/testdir/test_channel.vim @ 15404:440e5071f3f8 v8.1.0710

patch 8.1.0710: when using timers may wait for job exit quite long commit https://github.com/vim/vim/commit/c46af534102c65b43912311d67f55f5049e5ef7a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 9 22:24:49 2019 +0100 patch 8.1.0710: when using timers may wait for job exit quite long Problem: When using timers may wait for job exit quite long. Solution: Return from ui_wait_for_chars_or_timer() when a job or channel needs to be handled. (Ozaki Kiichi, closes #3783)
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Jan 2019 22:30:06 +0100
parents cda564e7c111
children 1d2b5c016f17
line wrap: on
line diff
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1893,3 +1893,40 @@ func Test_keep_pty_open()
   call assert_inrange(200, 1000, elapsed)
   call job_stop(job)
 endfunc
+
+func Test_job_start_in_timer()
+  if !has('job') || !has('timers')
+    return
+  endif
+
+  func OutCb(chan, msg)
+  endfunc
+
+  func ExitCb(job, status)
+    let g:val = 1
+    call Resume()
+  endfunc
+
+  func TimerCb(timer)
+    if has('win32')
+      let cmd = ['cmd', '/c', 'echo.']
+    else
+      let cmd = ['echo']
+    endif
+    let g:job = job_start(cmd, {'out_cb': 'OutCb', 'exit_cb': 'ExitCb'})
+    call substitute(repeat('a', 100000), '.', '', 'g')
+  endfunc
+
+  " We should be interrupted before 'updatetime' elapsed.
+  let g:val = 0
+  call timer_start(1, 'TimerCb')
+  let elapsed = Standby(&ut)
+  call assert_inrange(1, &ut / 2, elapsed)
+  call job_stop(g:job)
+
+  delfunc OutCb
+  delfunc ExitCb
+  delfunc TimerCb
+  unlet! g:val
+  unlet! g:job
+endfunc