Skip to content

Commit 4220555

Browse files
committed
patch 8.0.0477: the client-server test may hang when failing
Problem: The client-server test may hang when failing. Solution: Set a timer. Add assert_report()
1 parent 7a43cb9 commit 4220555

File tree

9 files changed

+149
-64
lines changed

9 files changed

+149
-64
lines changed

runtime/doc/eval.txt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2017 Mar 09
1+
*eval.txt* For Vim version 8.0. Last change: 2017 Mar 18
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1986,16 +1986,23 @@ argidx() Number current index in the argument list
19861986
arglistid([{winnr} [, {tabnr}]]) Number argument list id
19871987
argv({nr}) String {nr} entry of the argument list
19881988
argv() List the argument list
1989-
assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
1990-
assert_exception({error} [, {msg}]) none assert {error} is in v:exception
1991-
assert_fails({cmd} [, {error}]) none assert {cmd} fails
1992-
assert_false({actual} [, {msg}]) none assert {actual} is false
1989+
assert_equal({exp}, {act} [, {msg}])
1990+
none assert {exp} is equal to {act}
1991+
assert_exception({error} [, {msg}])
1992+
none assert {error} is in v:exception
1993+
assert_fails({cmd} [, {error}]) none assert {cmd} fails
1994+
assert_false({actual} [, {msg}])
1995+
none assert {actual} is false
19931996
assert_inrange({lower}, {upper}, {actual} [, {msg}])
19941997
none assert {actual} is inside the range
1995-
assert_match({pat}, {text} [, {msg}]) none assert {pat} matches {text}
1996-
assert_notequal({exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
1997-
assert_notmatch({pat}, {text} [, {msg}]) none assert {pat} not matches {text}
1998-
assert_true({actual} [, {msg}]) none assert {actual} is true
1998+
assert_match({pat}, {text} [, {msg}])
1999+
none assert {pat} matches {text}
2000+
assert_notequal({exp}, {act} [, {msg}])
2001+
none assert {exp} is not equal {act}
2002+
assert_notmatch({pat}, {text} [, {msg}])
2003+
none assert {pat} not matches {text}
2004+
assert_report({msg}) none report a test failure
2005+
assert_true({actual} [, {msg}]) none assert {actual} is true
19992006
asin({expr}) Float arc sine of {expr}
20002007
atan({expr}) Float arc tangent of {expr}
20012008
atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
@@ -2583,7 +2590,10 @@ assert_notmatch({pattern}, {actual} [, {msg}])
25832590
The opposite of `assert_match()`: add an error message to
25842591
|v:errors| when {pattern} matches {actual}.
25852592

2586-
assert_true({actual} [, {msg}]) *assert_true()*
2593+
assert_report({msg}) *assert_report()*
2594+
Report a test failure directly, using {msg}.
2595+
2596+
assert_true({actual} [, {msg}]) *assert_true()*
25872597
When {actual} is not true an error message is added to
25882598
|v:errors|, like with |assert_equal()|.
25892599
A value is TRUE when it is a non-zero number. When {actual}
@@ -3925,11 +3935,14 @@ foldtext() Returns a String, to be displayed for a closed fold. This is
39253935
|v:foldstart|, |v:foldend| and |v:folddashes| variables.
39263936
The returned string looks like this: >
39273937
+-- 45 lines: abcdef
3928-
< The number of dashes depends on the foldlevel. The "45" is
3929-
the number of lines in the fold. "abcdef" is the text in the
3930-
first non-blank line of the fold. Leading white space, "//"
3931-
or "/*" and the text from the 'foldmarker' and 'commentstring'
3932-
options is removed.
3938+
< The number of leading dashes depends on the foldlevel. The
3939+
"45" is the number of lines in the fold. "abcdef" is the text
3940+
in the first non-blank line of the fold. Leading white space,
3941+
"//" or "/*" and the text from the 'foldmarker' and
3942+
'commentstring' options is removed.
3943+
When used to draw the actual foldtext, the rest of the line
3944+
will be filled with the fold char from the 'fillchars'
3945+
setting.
39333946
{not available when compiled without the |+folding| feature}
39343947

39353948
foldtextresult({lnum}) *foldtextresult()*

src/eval.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9083,6 +9083,17 @@ assert_bool(typval_T *argvars, int isTrue)
90839083
}
90849084
}
90859085

9086+
void
9087+
assert_report(typval_T *argvars)
9088+
{
9089+
garray_T ga;
9090+
9091+
prepare_assert_error(&ga);
9092+
ga_concat(&ga, get_tv_string(&argvars[0]));
9093+
assert_error(&ga);
9094+
ga_clear(&ga);
9095+
}
9096+
90869097
void
90879098
assert_exception(typval_T *argvars)
90889099
{

src/evalfunc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static void f_assert_inrange(typval_T *argvars, typval_T *rettv);
5252
static void f_assert_match(typval_T *argvars, typval_T *rettv);
5353
static void f_assert_notequal(typval_T *argvars, typval_T *rettv);
5454
static void f_assert_notmatch(typval_T *argvars, typval_T *rettv);
55+
static void f_assert_report(typval_T *argvars, typval_T *rettv);
5556
static void f_assert_true(typval_T *argvars, typval_T *rettv);
5657
#ifdef FEAT_FLOAT
5758
static void f_asin(typval_T *argvars, typval_T *rettv);
@@ -483,6 +484,7 @@ static struct fst
483484
{"assert_match", 2, 3, f_assert_match},
484485
{"assert_notequal", 2, 3, f_assert_notequal},
485486
{"assert_notmatch", 2, 3, f_assert_notmatch},
487+
{"assert_report", 1, 1, f_assert_report},
486488
{"assert_true", 1, 2, f_assert_true},
487489
#ifdef FEAT_FLOAT
488490
{"atan", 1, 1, f_atan},
@@ -1313,6 +1315,15 @@ f_assert_notmatch(typval_T *argvars, typval_T *rettv UNUSED)
13131315
assert_match_common(argvars, ASSERT_NOTMATCH);
13141316
}
13151317

1318+
/*
1319+
* "assert_report(msg)" function
1320+
*/
1321+
static void
1322+
f_assert_report(typval_T *argvars, typval_T *rettv UNUSED)
1323+
{
1324+
assert_report(argvars);
1325+
}
1326+
13161327
/*
13171328
* "assert_true(actual[, msg])" function
13181329
*/

src/if_xcmdsrv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ ServerWait(
596596
if (seconds >= 0 && (now - start) >= seconds)
597597
break;
598598

599+
#ifdef FEAT_TIMERS
600+
check_due_timer();
601+
#endif
602+
599603
/* Just look out for the answer without calling back into Vim */
600604
if (localLoop)
601605
{

src/os_mswin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,9 @@ serverGetReply(HWND server, int *expr_res, int remove, int wait)
25702570
/* Loop until we receive a reply */
25712571
while (reply_received == 0)
25722572
{
2573+
#ifdef FEAT_TIMERS
2574+
check_due_timer();
2575+
#endif
25732576
/* Wait for a SendMessage() call to us. This could be the reply
25742577
* we are waiting for. Use a timeout of a second, to catch the
25752578
* situation that the server died unexpectedly. */

src/proto/eval.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void assert_equal_common(typval_T *argvars, assert_type_T atype);
123123
void assert_match_common(typval_T *argvars, assert_type_T atype);
124124
void assert_inrange(typval_T *argvars);
125125
void assert_bool(typval_T *argvars, int isTrue);
126+
void assert_report(typval_T *argvars);
126127
void assert_exception(typval_T *argvars);
127128
void assert_fails(typval_T *argvars);
128129
void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u *exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T atype);

src/testdir/runtest.vim

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function GetAllocId(name)
8686
return lnum - top - 1
8787
endfunc
8888

89-
function RunTheTest(test)
89+
func RunTheTest(test)
9090
echo 'Executing ' . a:test
9191

9292
" Avoid stopping at the "hit enter" prompt
@@ -142,6 +142,60 @@ function RunTheTest(test)
142142
set nomodified
143143
endfunc
144144

145+
func AfterTheTest()
146+
if len(v:errors) > 0
147+
let s:fail += 1
148+
call add(s:errors, 'Found errors in ' . s:test . ':')
149+
call extend(s:errors, v:errors)
150+
let v:errors = []
151+
endif
152+
endfunc
153+
154+
" This function can be called by a test if it wants to abort testing.
155+
func FinishTesting()
156+
call AfterTheTest()
157+
158+
" Don't write viminfo on exit.
159+
set viminfo=
160+
161+
if s:fail == 0
162+
" Success, create the .res file so that make knows it's done.
163+
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
164+
write
165+
endif
166+
167+
if len(s:errors) > 0
168+
" Append errors to test.log
169+
split test.log
170+
call append(line('$'), '')
171+
call append(line('$'), 'From ' . g:testname . ':')
172+
call append(line('$'), s:errors)
173+
write
174+
endif
175+
176+
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
177+
echo message
178+
call add(s:messages, message)
179+
if s:fail > 0
180+
let message = s:fail . ' FAILED:'
181+
echo message
182+
call add(s:messages, message)
183+
call extend(s:messages, s:errors)
184+
endif
185+
186+
" Add SKIPPED messages
187+
call extend(s:messages, s:skipped)
188+
189+
" Append messages to the file "messages"
190+
split messages
191+
call append(line('$'), '')
192+
call append(line('$'), 'From ' . g:testname . ':')
193+
call append(line('$'), s:messages)
194+
write
195+
196+
qall!
197+
endfunc
198+
145199
" Source the test script. First grab the file name, in case the script
146200
" navigates away. g:testname can be used by the tests.
147201
let g:testname = expand('%')
@@ -164,6 +218,7 @@ endif
164218

165219
" Names of flaky tests.
166220
let s:flaky = [
221+
\ 'Test_client_server()',
167222
\ 'Test_close_and_exit_cb()',
168223
\ 'Test_collapse_buffers()',
169224
\ 'Test_communicate()',
@@ -197,52 +252,9 @@ for s:test in sort(s:tests)
197252
call RunTheTest(s:test)
198253
endif
199254

200-
if len(v:errors) > 0
201-
let s:fail += 1
202-
call add(s:errors, 'Found errors in ' . s:test . ':')
203-
call extend(s:errors, v:errors)
204-
let v:errors = []
205-
endif
255+
call AfterTheTest()
206256
endfor
207257

208-
" Don't write viminfo on exit.
209-
set viminfo=
210-
211-
if s:fail == 0
212-
" Success, create the .res file so that make knows it's done.
213-
exe 'split ' . fnamemodify(g:testname, ':r') . '.res'
214-
write
215-
endif
216-
217-
if len(s:errors) > 0
218-
" Append errors to test.log
219-
split test.log
220-
call append(line('$'), '')
221-
call append(line('$'), 'From ' . g:testname . ':')
222-
call append(line('$'), s:errors)
223-
write
224-
endif
225-
226-
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test')
227-
echo message
228-
call add(s:messages, message)
229-
if s:fail > 0
230-
let message = s:fail . ' FAILED:'
231-
echo message
232-
call add(s:messages, message)
233-
call extend(s:messages, s:errors)
234-
endif
235-
236-
" Add SKIPPED messages
237-
call extend(s:messages, s:skipped)
238-
239-
" Append messages to the file "messages"
240-
split messages
241-
call append(line('$'), '')
242-
call append(line('$'), 'From ' . g:testname . ':')
243-
call append(line('$'), s:messages)
244-
write
245-
246-
qall!
258+
call FinishTesting()
247259

248260
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_clientserver.vim

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,87 @@ endif
66

77
source shared.vim
88

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+
915
func Test_client_server()
1016
let cmd = GetVimCommand()
1117
if cmd == ''
1218
return
1319
endif
14-
let name = 'XVIMTEXT'
20+
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'
1526
let cmd .= ' --servername ' . name
1627
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
1728
call WaitFor('job_status(g:job) == "run"')
1829
if job_status(g:job) != 'run'
19-
call assert_true(0, 'Cannot run the Vim server')
30+
call assert_report('Cannot run the Vim server')
2031
return
2132
endif
33+
let s:where = 2
2234

2335
" Takes a short while for the server to be active.
2436
call WaitFor('serverlist() =~ "' . name . '"')
2537
call assert_match(name, serverlist())
38+
let s:where = 3
2639

2740
call remote_foreground(name)
41+
let s:where = 4
2842

2943
call remote_send(name, ":let testvar = 'yes'\<CR>")
44+
let s:where = 5
3045
call WaitFor('remote_expr("' . name . '", "testvar") == "yes"')
46+
let s:where = 6
3147
call assert_equal('yes', remote_expr(name, "testvar"))
48+
let s:where = 7
3249

3350
if has('unix') && has('gui') && !has('gui_running')
3451
" Running in a terminal and the GUI is avaiable: Tell the server to open
3552
" the GUI and check that the remote command still works.
3653
" Need to wait for the GUI to start up, otherwise the send hangs in trying
3754
" to send to the terminal window.
3855
call remote_send(name, ":gui -f\<CR>")
56+
let s:where = 8
3957
sleep 500m
4058
call remote_send(name, ":let testvar = 'maybe'\<CR>")
59+
let s:where = 9
4160
call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"')
61+
let s:where = 10
4262
call assert_equal('maybe', remote_expr(name, "testvar"))
63+
let s:where = 11
4364
endif
4465

4566
call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
67+
let s:where = 12
4668

4769
" Expression evaluated locally.
4870
if v:servername == ''
4971
call remote_startserver('MYSELF')
72+
let s:where = 13
5073
call assert_equal('MYSELF', v:servername)
5174
endif
5275
let g:testvar = 'myself'
5376
call assert_equal('myself', remote_expr(v:servername, 'testvar'))
77+
let s:where = 14
5478

5579
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
80+
let s:where = 15
5681
call assert_equal('got it', remote_read(g:myserverid))
82+
let s:where = 16
5783

5884
call remote_send(name, ":qa!\<CR>")
85+
let s:where = 17
5986
call WaitFor('job_status(g:job) == "dead"')
87+
let s:where = 18
6088
if job_status(g:job) != 'dead'
61-
call assert_true(0, 'Server did not exit')
89+
call assert_report('Server did not exit')
6290
call job_stop(g:job, 'kill')
6391
endif
6492
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
477,
767769
/**/
768770
476,
769771
/**/

0 commit comments

Comments
 (0)