diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-05-17 18:16:45 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-06-18 10:49:38 +0200 |
commit | d4938743e6aef04c83d02907048768d0d79aaa30 (patch) | |
tree | afdd0cbd21e494e48da65d346c67aa68416e0b31 /test/functional/core/job_spec.lua | |
parent | 4946751906370134cd02e8da0736bef221171172 (diff) | |
download | rneovim-d4938743e6aef04c83d02907048768d0d79aaa30.tar.gz rneovim-d4938743e6aef04c83d02907048768d0d79aaa30.tar.bz2 rneovim-d4938743e6aef04c83d02907048768d0d79aaa30.zip |
channel: refactor events, prevent recursive invocation of events
Diffstat (limited to 'test/functional/core/job_spec.lua')
-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 |