changeset 9933:7f38e72a9d65 v7.4.2240

commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 22 21:40:29 2016 +0200 patch 7.4.2240 Problem: Tests using the sleep time can be flaky. Solution: Use reltime() if available. (Partly by Shane Harper)
author Christian Brabandt <cb@256bit.org>
date Mon, 22 Aug 2016 21:45:06 +0200
parents 1aabb9543319
children a9608b2c4a2d
files src/testdir/shared.vim src/testdir/test_timers.vim src/version.c
diffstat 3 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/shared.vim
+++ b/src/testdir/shared.vim
@@ -109,19 +109,31 @@ func s:kill_server(cmd)
 endfunc
 
 " 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)
+	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
 
 " Run Vim, using the "vimcmd" file and "-u NORC".
--- a/src/testdir/test_timers.vim
+++ b/src/testdir/test_timers.vim
@@ -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(80, 200, 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()
@@ -109,7 +121,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
--- a/src/version.c
+++ b/src/version.c
@@ -764,6 +764,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2240,
+/**/
     2239,
 /**/
     2238,