Mercurial > vim
comparison src/testdir/test_clientserver.vim @ 11211:71311d899b42 v8.0.0492
patch 8.0.0492: a failing client-server request can make Vim hang
commit https://github.com/vim/vim/commit/81b9d0bd5c705815e903e671e81b0b05828efd9c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 19 21:20:53 2017 +0100
patch 8.0.0492: a failing client-server request can make Vim hang
Problem: A failing client-server request can make Vim hang.
Solution: Add a timeout argument to functions that wait.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 19 Mar 2017 21:30:05 +0100 |
parents | eb050472e4b4 |
children | 9612b93820a4 |
comparison
equal
deleted
inserted
replaced
11210:5ffe3a7f9bd7 | 11211:71311d899b42 |
---|---|
4 finish | 4 finish |
5 endif | 5 endif |
6 | 6 |
7 source shared.vim | 7 source shared.vim |
8 | 8 |
9 let s:where = 0 | |
10 func Abort(id) | |
11 call assert_report('Test timed out at ' . s:where) | |
12 call FinishTesting() | |
13 endfunc | |
14 | |
15 func Test_client_server() | 9 func Test_client_server() |
16 let cmd = GetVimCommand() | 10 let cmd = GetVimCommand() |
17 if cmd == '' | 11 if cmd == '' |
18 return | 12 return |
19 endif | 13 endif |
20 | 14 |
21 " Some of these commands may hang when failing. | |
22 call timer_start(10000, 'Abort') | |
23 | |
24 let s:where = 1 | |
25 let name = 'XVIMTEST' | 15 let name = 'XVIMTEST' |
26 let cmd .= ' --servername ' . name | 16 let cmd .= ' --servername ' . name |
27 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) | 17 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) |
28 call WaitFor('job_status(g:job) == "run"') | 18 call WaitFor('job_status(g:job) == "run"') |
29 if job_status(g:job) != 'run' | 19 if job_status(g:job) != 'run' |
30 call assert_report('Cannot run the Vim server') | 20 call assert_report('Cannot run the Vim server') |
31 return | 21 return |
32 endif | 22 endif |
33 let s:where = 2 | |
34 | 23 |
35 " Takes a short while for the server to be active. | 24 " Takes a short while for the server to be active. |
36 call WaitFor('serverlist() =~ "' . name . '"') | 25 call WaitFor('serverlist() =~ "' . name . '"') |
37 call assert_match(name, serverlist()) | 26 call assert_match(name, serverlist()) |
38 let s:where = 3 | |
39 | 27 |
40 call remote_foreground(name) | 28 call remote_foreground(name) |
41 let s:where = 4 | |
42 | 29 |
43 call remote_send(name, ":let testvar = 'yes'\<CR>") | 30 call remote_send(name, ":let testvar = 'yes'\<CR>") |
44 let s:where = 5 | 31 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "yes"') |
45 call WaitFor('remote_expr("' . name . '", "testvar") == "yes"') | 32 call assert_equal('yes', remote_expr(name, "testvar", "", 2)) |
46 let s:where = 6 | |
47 call assert_equal('yes', remote_expr(name, "testvar")) | |
48 let s:where = 7 | |
49 | 33 |
50 if has('unix') && has('gui') && !has('gui_running') | 34 if has('unix') && has('gui') && !has('gui_running') |
51 " Running in a terminal and the GUI is avaiable: Tell the server to open | 35 " Running in a terminal and the GUI is avaiable: Tell the server to open |
52 " the GUI and check that the remote command still works. | 36 " the GUI and check that the remote command still works. |
53 " Need to wait for the GUI to start up, otherwise the send hangs in trying | 37 " Need to wait for the GUI to start up, otherwise the send hangs in trying |
54 " to send to the terminal window. | 38 " to send to the terminal window. |
55 call remote_send(name, ":gui -f\<CR>") | 39 if has('gui_athena') || has('gui_motif') |
56 let s:where = 8 | 40 " For those GUIs, ignore the 'failed to create input context' error. |
57 sleep 500m | 41 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") |
42 else | |
43 call remote_send(name, ":gui -f\<CR>") | |
44 endif | |
45 " Wait for the server to be up and answering requests. | |
46 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""') | |
47 | |
58 call remote_send(name, ":let testvar = 'maybe'\<CR>") | 48 call remote_send(name, ":let testvar = 'maybe'\<CR>") |
59 let s:where = 9 | 49 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"') |
60 call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"') | 50 call assert_equal('maybe', remote_expr(name, "testvar", "", 2)) |
61 let s:where = 10 | |
62 call assert_equal('maybe', remote_expr(name, "testvar")) | |
63 let s:where = 11 | |
64 endif | 51 endif |
65 | 52 |
66 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241') | 53 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241') |
67 let s:where = 12 | |
68 | 54 |
69 " Expression evaluated locally. | 55 " Expression evaluated locally. |
70 if v:servername == '' | 56 if v:servername == '' |
71 call remote_startserver('MYSELF') | 57 call remote_startserver('MYSELF') |
72 let s:where = 13 | 58 " May get MYSELF1 when running the test again. |
73 call assert_equal('MYSELF', v:servername) | 59 call assert_match('MYSELF', v:servername) |
74 endif | 60 endif |
75 let g:testvar = 'myself' | 61 let g:testvar = 'myself' |
76 call assert_equal('myself', remote_expr(v:servername, 'testvar')) | 62 call assert_equal('myself', remote_expr(v:servername, 'testvar')) |
77 let s:where = 14 | |
78 | 63 |
79 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid') | 64 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid') |
80 let s:where = 15 | 65 call assert_equal('got it', remote_read(g:myserverid, 2)) |
81 call assert_equal('got it', remote_read(g:myserverid)) | |
82 let s:where = 16 | |
83 | 66 |
84 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid') | 67 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid') |
85 let s:where = 151 | |
86 let peek_result = 'nothing' | 68 let peek_result = 'nothing' |
87 let r = remote_peek(g:myserverid, 'peek_result') | 69 let r = remote_peek(g:myserverid, 'peek_result') |
88 let s:where = 161 | |
89 " unpredictable whether the result is already avaialble. | 70 " unpredictable whether the result is already avaialble. |
90 if r > 0 | 71 if r > 0 |
91 call assert_equal('another', peek_result) | 72 call assert_equal('another', peek_result) |
92 elseif r == 0 | 73 elseif r == 0 |
93 call assert_equal('nothing', peek_result) | 74 call assert_equal('nothing', peek_result) |
94 else | 75 else |
95 call assert_report('remote_peek() failed') | 76 call assert_report('remote_peek() failed') |
96 endif | 77 endif |
97 let g:peek_result = 'empty' | 78 let g:peek_result = 'empty' |
98 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0') | 79 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0') |
99 let s:where = 171 | |
100 call assert_equal('another', g:peek_result) | 80 call assert_equal('another', g:peek_result) |
101 let s:where = 181 | 81 call assert_equal('another', remote_read(g:myserverid, 2)) |
102 call assert_equal('another', remote_read(g:myserverid)) | |
103 let s:where = 191 | |
104 | 82 |
105 call remote_send(name, ":qa!\<CR>") | 83 call remote_send(name, ":qa!\<CR>") |
106 let s:where = 17 | |
107 call WaitFor('job_status(g:job) == "dead"') | 84 call WaitFor('job_status(g:job) == "dead"') |
108 let s:where = 18 | |
109 if job_status(g:job) != 'dead' | 85 if job_status(g:job) != 'dead' |
110 call assert_report('Server did not exit') | 86 call assert_report('Server did not exit') |
111 call job_stop(g:job, 'kill') | 87 call job_stop(g:job, 'kill') |
112 endif | 88 endif |
113 endfunc | 89 endfunc |