1
0
forked from aniani/vim

patch 7.4.2240

Problem:    Tests using the sleep time can be flaky.
Solution:   Use reltime() if available. (Partly by Shane Harper)
This commit is contained in:
Bram Moolenaar
2016-08-22 21:40:29 +02:00
parent 9baf297c99
commit f267f8bdf7
3 changed files with 37 additions and 7 deletions

View File

@@ -109,19 +109,31 @@ func s:kill_server(cmd)
endfunc endfunc
" Wait for up to a second for "expr" to become true. " Wait for up to a second for "expr" to become true.
" Return time slept in milliseconds. " Return time slept in milliseconds. With the +reltime feature this can be
" more than the actual waiting time. Without +reltime it can also be less.
func WaitFor(expr) func WaitFor(expr)
let slept = 0 " using reltime() is more accurate, but not always available
if has('reltime')
let start = reltime()
else
let slept = 0
endif
for i in range(100) for i in range(100)
try try
if eval(a:expr) if eval(a:expr)
if has('reltime')
return float2nr(reltimefloat(reltime(start)) * 1000)
endif
return slept return slept
endif endif
catch catch
endtry endtry
let slept += 10 if !has('reltime')
let slept += 10
endif
sleep 10m sleep 10m
endfor endfor
return 1000
endfunc endfunc
" Run Vim, using the "vimcmd" file and "-u NORC". " Run Vim, using the "vimcmd" file and "-u NORC".

View File

@@ -19,7 +19,11 @@ func Test_oneshot()
let timer = timer_start(50, 'MyHandler') let timer = timer_start(50, 'MyHandler')
let slept = WaitFor('g:val == 1') let slept = WaitFor('g:val == 1')
call assert_equal(1, g:val) call assert_equal(1, g:val)
call assert_inrange(30, 100, slept) if has('reltime')
call assert_inrange(50, 100, slept)
else
call assert_inrange(20, 100, slept)
endif
endfunc endfunc
func Test_repeat_three() func Test_repeat_three()
@@ -27,7 +31,11 @@ func Test_repeat_three()
let timer = timer_start(50, 'MyHandler', {'repeat': 3}) let timer = timer_start(50, 'MyHandler', {'repeat': 3})
let slept = WaitFor('g:val == 3') let slept = WaitFor('g:val == 3')
call assert_equal(3, g:val) call assert_equal(3, g:val)
call assert_inrange(80, 200, slept) if has('reltime')
call assert_inrange(150, 200, slept)
else
call assert_inrange(80, 200, slept)
endif
endfunc endfunc
func Test_repeat_many() func Test_repeat_many()
@@ -48,7 +56,11 @@ func Test_with_partial_callback()
call timer_start(50, s:meow.bite) call timer_start(50, s:meow.bite)
let slept = WaitFor('g:val == 1') let slept = WaitFor('g:val == 1')
call assert_equal(1, g:val) call assert_equal(1, g:val)
call assert_inrange(30, 100, slept) if has('reltime')
call assert_inrange(50, 100, slept)
else
call assert_inrange(20, 100, slept)
endif
endfunc endfunc
func Test_retain_partial() func Test_retain_partial()
@@ -109,7 +121,11 @@ func Test_paused()
let slept = WaitFor('g:val == 1') let slept = WaitFor('g:val == 1')
call assert_equal(1, g:val) call assert_equal(1, g:val)
call assert_inrange(0, 10, slept) if has('reltime')
call assert_inrange(0, 30, slept)
else
call assert_inrange(0, 10, slept)
endif
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -763,6 +763,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2240,
/**/ /**/
2239, 2239,
/**/ /**/