diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-18 09:50:44 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-05-18 15:48:13 +0200 |
commit | 7669fc1e9b9dba015597974f4a2b46f2439b48da (patch) | |
tree | 3fe14d0eac1881c552c3fb6e732e84cf4d5da147 | |
parent | bba75eb184cee3d96264a392e2083f5b50732214 (diff) | |
download | rneovim-7669fc1e9b9dba015597974f4a2b46f2439b48da.tar.gz rneovim-7669fc1e9b9dba015597974f4a2b46f2439b48da.tar.bz2 rneovim-7669fc1e9b9dba015597974f4a2b46f2439b48da.zip |
test: share implementation of testdir/load.vim
Also, don't compute load factor unless load_adjust() was called, it
slows down the test suite.
ref #9292
-rw-r--r-- | src/nvim/testdir/load.vim | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_timers.vim | 14 | ||||
-rw-r--r-- | test/functional/helpers.lua | 39 |
3 files changed, 15 insertions, 44 deletions
diff --git a/src/nvim/testdir/load.vim b/src/nvim/testdir/load.vim index 2e01338dd0..6369b8f45e 100644 --- a/src/nvim/testdir/load.vim +++ b/src/nvim/testdir/load.vim @@ -1,3 +1,5 @@ +" Also used by: test/functional/helpers.lua + function! s:load_factor() abort let timeout = 200 let times = [] @@ -23,8 +25,8 @@ function! s:load_factor() abort endfunction " Compute load factor only once. -let s:load_factor = s:load_factor() +let g:test_load_factor = s:load_factor() function! LoadAdjust(num) abort - return float2nr(ceil(a:num * s:load_factor)) + return float2nr(ceil(a:num * g:test_load_factor)) endfunction diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 5b5f001e6b..9384989a35 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -15,17 +15,13 @@ func MyHandlerWithLists(lists, timer) let x = string(a:lists) endfunc -func s:assert_inrange(lower, upper, actual) - return assert_inrange(a:lower, LoadAdjust(a:upper), a:actual) -endfunc - func Test_oneshot() let g:val = 0 let timer = timer_start(50, 'MyHandler') let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call s:assert_inrange(40, 120, slept) + call assert_inrange(40, LoadAdjust(120), slept) else call assert_inrange(20, 120, slept) endif @@ -37,7 +33,7 @@ func Test_repeat_three() let slept = WaitFor('g:val == 3') call assert_equal(3, g:val) if has('reltime') - call s:assert_inrange(120, 250, slept) + call assert_inrange(120, LoadAdjust(250), slept) else call assert_inrange(80, 200, slept) endif @@ -52,7 +48,7 @@ func Test_repeat_many() endif sleep 200m call timer_stop(timer) - call s:assert_inrange((has('mac') ? 1 : 2), 4, g:val) + call assert_inrange((has('mac') ? 1 : 2), LoadAdjust(4), g:val) endfunc func Test_with_partial_callback() @@ -66,7 +62,7 @@ func Test_with_partial_callback() let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call s:assert_inrange(40, 130, slept) + call assert_inrange(40, LoadAdjust(130), slept) else call assert_inrange(20, 100, slept) endif @@ -129,7 +125,7 @@ func Test_paused() let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call s:assert_inrange(0, 140, slept) + call assert_inrange(0, LoadAdjust(140), slept) else call assert_inrange(0, 10, slept) endif diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index ae11455b3e..101d456165 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -739,41 +739,14 @@ local function alter_slashes(obj) end end -local function compute_load_factor() - local timeout = 200 - local times = {} - - clear() - - for _ = 1, 5 do - source([[ - let g:val = 0 - call timer_start(200, {-> nvim_set_var('val', 1)}) - let start = reltime() - while 1 - sleep 10m - if g:val == 1 - let g:waited_in_ms = float2nr(reltimefloat(reltime(start)) * 1000) - break - endif - endwhile - ]]) - table.insert(times, nvim_eval('g:waited_in_ms')) - end - - session:close() - session = nil - - local longest = math.max(unpack(times)) - local factor = (longest + 50.0) / timeout - - return factor -end - --- Compute load factor only once. -local load_factor = compute_load_factor() +local load_factor = nil local function load_adjust(num) + if load_factor == nil then -- Compute load factor only once. + clear() + request('nvim_command', 'source src/nvim/testdir/load.vim') + load_factor = request('nvim_eval', 'g:test_load_factor') + end return math.ceil(num * load_factor) end |