diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-06-18 13:58:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-18 13:58:14 +0200 |
commit | 149dcbf2c762abaa71d78c5684c7a7a4bb0fd567 (patch) | |
tree | 12daac0a309d6fb6029b71040da5f19e4d5c656e /test/functional | |
parent | 25e04c1d981e737b9f6e30d3b7a62954d81101ab (diff) | |
parent | d4938743e6aef04c83d02907048768d0d79aaa30 (diff) | |
download | rneovim-149dcbf2c762abaa71d78c5684c7a7a4bb0fd567.tar.gz rneovim-149dcbf2c762abaa71d78c5684c7a7a4bb0fd567.tar.bz2 rneovim-149dcbf2c762abaa71d78c5684c7a7a4bb0fd567.zip |
Merge pull request #10021 from bfredl/chanevent
channel: refactor events, prevent recursive invocation of callbacks
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/core/job_spec.lua | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index eb02610df0..86466415e5 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -439,16 +439,66 @@ describe('jobs', function() call add(self.data, Normalize(a:data)) sleep 200m endfunction + function! d.on_exit(job, data, event) dict + let g:exit_data = copy(self.data) + endfunction + if has('win32') + let cmd = 'for /L %I in (1,1,5) do @(echo %I& ping -n 2 127.0.0.1 > nul)' + else + let cmd = ['sh', '-c', 'for i in $(seq 1 5); do echo $i; sleep 0.1; done'] + endif + let g:id = jobstart(cmd, d) + sleep 1500m + call jobwait([g:id]) + ]]) + + local expected = {'1', '2', '3', '4', '5', ''} + local chunks = eval('d.data') + -- check nothing was received after exit, including EOF + eq(eval('g:exit_data'), chunks) + local received = {''} + for i, chunk in ipairs(chunks) do + if i < #chunks then + -- if chunks got joined, a spurious [''] callback was not sent + neq({''}, chunk) + else + -- but EOF callback is still sent + eq({''}, chunk) + end + received[#received] = received[#received]..chunk[1] + for j = 2, #chunk do + received[#received+1] = chunk[j] + end + end + eq(expected, received) + end) + + it('does not invoke callbacks recursively', function() + source([[ + let d = {'data': []} + function! d.on_stdout(job, data, event) dict + " if callbacks were invoked recursively, this would cause on_stdout + " to be invoked recursively and the data reversed on the call stack + sleep 200m + call add(self.data, Normalize(a:data)) + endfunction + function! d.on_exit(job, data, event) dict + let g:exit_data = copy(self.data) + endfunction if has('win32') let cmd = 'for /L %I in (1,1,5) do @(echo %I& ping -n 2 127.0.0.1 > nul)' else let cmd = ['sh', '-c', 'for i in $(seq 1 5); do echo $i; sleep 0.1; done'] endif - call jobwait([jobstart(cmd, d)]) + let g:id = jobstart(cmd, d) + sleep 1500m + call jobwait([g:id]) ]]) local expected = {'1', '2', '3', '4', '5', ''} local chunks = eval('d.data') + -- check nothing was received after exit, including EOF + eq(eval('g:exit_data'), chunks) local received = {''} for i, chunk in ipairs(chunks) do if i < #chunks then |