aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-01-17 23:24:03 +0100
committerGitHub <noreply@github.com>2019-01-17 23:24:03 +0100
commit8093cbd8e8ca06ce5c9d8814fc6d94cb2304133a (patch)
tree0a803cb317580bdb27533bd9550440e3ebcd84ff
parenta8a38f346548f507f06ff07d790d87913007523f (diff)
parent06785da5b611d750314caf152a5acdaa60ddf1b7 (diff)
downloadrneovim-8093cbd8e8ca06ce5c9d8814fc6d94cb2304133a.tar.gz
rneovim-8093cbd8e8ca06ce5c9d8814fc6d94cb2304133a.tar.bz2
rneovim-8093cbd8e8ca06ce5c9d8814fc6d94cb2304133a.zip
Merge #9292 from mhinz/xcode10
-rw-r--r--.travis.yml4
-rw-r--r--src/nvim/testdir/load.vim30
-rw-r--r--src/nvim/testdir/test_autocmd.vim6
-rw-r--r--src/nvim/testdir/test_help_tagjump.vim4
-rw-r--r--src/nvim/testdir/test_lambda.vim16
-rw-r--r--src/nvim/testdir/test_timers.vim13
-rw-r--r--test/functional/eval/timer_spec.lua29
-rw-r--r--test/functional/helpers.lua39
8 files changed, 112 insertions, 29 deletions
diff --git a/.travis.yml b/.travis.yml
index e6b9516b6e..bcc5c11930 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -70,10 +70,10 @@ jobs:
env: BUILD_32BIT=ON
- os: osx
compiler: clang
- osx_image: xcode9.4 # macOS 10.13
+ osx_image: xcode10.1 # macOS 10.13
- os: osx
compiler: gcc
- osx_image: xcode9.4 # macOS 10.13
+ osx_image: xcode10.1 # macOS 10.13
- if: branch = master
os: linux
env: CI_TARGET=lint
diff --git a/src/nvim/testdir/load.vim b/src/nvim/testdir/load.vim
new file mode 100644
index 0000000000..2e01338dd0
--- /dev/null
+++ b/src/nvim/testdir/load.vim
@@ -0,0 +1,30 @@
+function! s:load_factor() abort
+ let timeout = 200
+ let times = []
+
+ for _ in range(5)
+ let g:val = 0
+ call timer_start(timeout, {-> 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
+ call insert(times, g:waited_in_ms, 0)
+ endfor
+
+ let longest = max(times)
+ let factor = (longest + 50.0) / timeout
+
+ return factor
+endfunction
+
+" Compute load factor only once.
+let s:load_factor = s:load_factor()
+
+function! LoadAdjust(num) abort
+ return float2nr(ceil(a:num * s:load_factor))
+endfunction
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index 253d6750ed..f1fb8e67b9 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -18,6 +18,8 @@ func Test_vim_did_enter()
endfunc
if has('timers')
+ source load.vim
+
func ExitInsertMode(id)
call feedkeys("\<Esc>")
endfunc
@@ -29,7 +31,7 @@ if has('timers')
let g:triggered = 0
au CursorHoldI * let g:triggered += 1
set updatetime=20
- call timer_start(100, 'ExitInsertMode')
+ call timer_start(LoadAdjust(100), 'ExitInsertMode')
call feedkeys('a', 'x!')
call assert_equal(1, g:triggered)
au! CursorHoldI
@@ -40,7 +42,7 @@ if has('timers')
let g:triggered = 0
au CursorHoldI * let g:triggered += 1
set updatetime=20
- call timer_start(100, 'ExitInsertMode')
+ call timer_start(LoadAdjust(100), 'ExitInsertMode')
" CursorHoldI does not trigger after CTRL-X
call feedkeys("a\<C-X>", 'x!')
call assert_equal(0, g:triggered)
diff --git a/src/nvim/testdir/test_help_tagjump.vim b/src/nvim/testdir/test_help_tagjump.vim
index c873487b92..a6494c531c 100644
--- a/src/nvim/testdir/test_help_tagjump.vim
+++ b/src/nvim/testdir/test_help_tagjump.vim
@@ -28,9 +28,9 @@ func Test_help_tagjump()
call assert_true(getline('.') =~ '\*quotestar\*')
helpclose
- help sp?it
+ help ch?ckhealth
call assert_equal("help", &filetype)
- call assert_true(getline('.') =~ '\*'.(has('win32') ? 'split()' : ':split').'\*')
+ call assert_true(getline('.') =~ '\*:checkhealth\*')
helpclose
help :?
diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim
index 6e07c874b4..ada25da4a8 100644
--- a/src/nvim/testdir/test_lambda.vim
+++ b/src/nvim/testdir/test_lambda.vim
@@ -23,6 +23,8 @@ function! Test_lambda_with_timer()
return
endif
+ source load.vim
+
let s:n = 0
let s:timer_id = 0
function! s:Foo()
@@ -31,15 +33,19 @@ function! Test_lambda_with_timer()
endfunction
call s:Foo()
- sleep 210ms
+ sleep 210m
" do not collect lambda
call test_garbagecollect_now()
- let m = s:n
- sleep 230ms
+ let m = LoadAdjust(s:n)
+ sleep 230m
call timer_stop(s:timer_id)
+
+ let n = LoadAdjust(s:n)
+ let nine = LoadAdjust(9)
+
call assert_true(m > 1)
- call assert_true(s:n > m + 1)
- call assert_true(s:n < 9)
+ call assert_true(n > m + 1)
+ call assert_true(n < nine)
endfunction
function! Test_lambda_with_partial()
diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim
index cdfdd473b9..62ddad5dce 100644
--- a/src/nvim/testdir/test_timers.vim
+++ b/src/nvim/testdir/test_timers.vim
@@ -5,6 +5,7 @@ if !has('timers')
endif
source shared.vim
+source load.vim
func MyHandler(timer)
let g:val += 1
@@ -14,13 +15,17 @@ 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 assert_inrange(40, 120, slept)
+ call s:assert_inrange(40, 120, slept)
else
call assert_inrange(20, 120, slept)
endif
@@ -32,7 +37,7 @@ func Test_repeat_three()
let slept = WaitFor('g:val == 3')
call assert_equal(3, g:val)
if has('reltime')
- call assert_inrange(120, 250, slept)
+ call s:assert_inrange(120, 250, slept)
else
call assert_inrange(80, 200, slept)
endif
@@ -58,7 +63,7 @@ func Test_with_partial_callback()
let slept = WaitFor('g:val == 1')
call assert_equal(1, g:val)
if has('reltime')
- call assert_inrange(40, 130, slept)
+ call s:assert_inrange(40, 130, slept)
else
call assert_inrange(20, 100, slept)
endif
@@ -121,7 +126,7 @@ func Test_paused()
let slept = WaitFor('g:val == 1')
call assert_equal(1, g:val)
if has('reltime')
- call assert_inrange(0, 140, slept)
+ call s:assert_inrange(0, 140, slept)
else
call assert_inrange(0, 10, slept)
endif
diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua
index 124b9625c3..ce0e24d8d7 100644
--- a/test/functional/eval/timer_spec.lua
+++ b/test/functional/eval/timer_spec.lua
@@ -4,6 +4,7 @@ local feed, eq, eval = helpers.feed, helpers.eq, helpers.eval
local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
local curbufmeths = helpers.curbufmeths
+local load_adjust = helpers.load_adjust
describe('timers', function()
before_each(function()
@@ -19,14 +20,14 @@ describe('timers', function()
it('works one-shot', function()
command("call timer_start(50, 'MyHandler')")
eq(0,eval("g:val"))
- run(nil, nil, nil, 200)
+ run(nil, nil, nil, load_adjust(200))
eq(1,eval("g:val"))
end)
it('works one-shot when repeat=0', function()
command("call timer_start(50, 'MyHandler', {'repeat': 0})")
eq(0,eval("g:val"))
- run(nil, nil, nil, 200)
+ run(nil, nil, nil, load_adjust(200))
eq(1,eval("g:val"))
end)
@@ -34,7 +35,7 @@ describe('timers', function()
it('works with repeat two', function()
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
eq(0,eval("g:val"))
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(2,eval("g:val"))
end)
@@ -42,14 +43,14 @@ describe('timers', function()
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
nvim_async("command", "sleep 10")
eq(0,eval("g:val"))
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(2,eval("g:val"))
end)
it('works with zero timeout', function()
-- timer_start does still not invoke the callback immediately
eq(0,eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]"))
- run(nil, nil, nil, 400)
+ run(nil, nil, nil, load_adjust(400))
eq(1000,eval("g:val"))
end)
@@ -58,18 +59,18 @@ describe('timers', function()
-- this also tests that remote requests works during sleep
eval("timer_start(50, 'MyHandler', {'repeat': 2})")
eq(0,eval("g:val"))
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(2,eval("g:val"))
end)
it('are paused when event processing is disabled', function()
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
- run(nil, nil, nil, 100)
+ run(nil, nil, nil, load_adjust(100))
local count = eval("g:val")
-- shows two line error message and thus invokes the return prompt.
-- if we start to allow event processing here, we need to change this test.
feed(':throw "fatal error"<CR>')
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
feed("<cr>")
local diff = eval("g:val") - count
assert(0 <= diff and diff <= 4,
@@ -79,7 +80,7 @@ describe('timers', function()
it('are triggered in blocking getchar() call', function()
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
nvim_async("command", "let g:c = getchar()")
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
feed("c")
local count = eval("g:val")
assert(count >= 3, 'expected count >= 3, got: '..tostring(count))
@@ -137,10 +138,10 @@ describe('timers', function()
it('can be stopped', function()
local t = eval("timer_start(50, 'MyHandler', {'repeat': -1})")
eq(0,eval("g:val"))
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
funcs.timer_stop(t)
local count = eval("g:val")
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
local count2 = eval("g:val")
-- when count is eval:ed after timer_stop this should be non-racy
eq(count, count2)
@@ -161,7 +162,7 @@ describe('timers', function()
]])
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
eq(0,eval("g:val"))
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(3,eval("g:val"))
end)
@@ -174,7 +175,7 @@ describe('timers', function()
]])
command("call timer_start(20, 'MyHandler', {'repeat': 3})")
command("call timer_start(40, 'MyHandler2', {'repeat': 2})")
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(3,eval("g:val"))
eq(2,eval("g:val2"))
end)
@@ -189,7 +190,7 @@ describe('timers', function()
endfunc
]])
command("call timer_start(5, 'MyHandler', {'repeat': 1})")
- run(nil, nil, nil, 300)
+ run(nil, nil, nil, load_adjust(300))
eq(1,eval("g:val"))
end)
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index ec5c83fa92..3e72ba6f98 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -678,6 +678,44 @@ 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 function load_adjust(num)
+ return math.ceil(num * load_factor)
+end
+
local module = {
NIL = mpack.NIL,
alter_slashes = alter_slashes,
@@ -719,6 +757,7 @@ local module = {
meths = meths,
missing_provider = missing_provider,
mkdir = lfs.mkdir,
+ load_adjust = load_adjust,
near = near,
neq = neq,
new_pipename = new_pipename,