vim-patch:7.4.2240

Problem:    Tests using the sleep time can be flaky.
Solution:   Use reltime() if available. (Partly by Shane Harper)

f267f8bdf7
This commit is contained in:
Jurica Bradaric 2017-03-20 20:52:54 +01:00
parent 420a9955fa
commit 5c2f1e29e3
3 changed files with 37 additions and 10 deletions

View File

@ -1,17 +1,28 @@
" Functions shared by several tests.
" 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)
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)
try
if eval(a:expr)
return slept
if has('reltime')
return float2nr(reltimefloat(reltime(start)) * 1000)
endif
return slept
endif
catch
endtry
let slept += 10
if !has('reltime')
let slept += 10
endif
sleep 10m
endfor
return 1000
endfunc

View File

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

View File

@ -201,7 +201,7 @@ static int included_patches[] = {
// 2243 NA
// 2242,
// 2241,
// 2240,
2240,
// 2239,
// 2238 NA
2237,