aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/eval/timer_spec.lua29
-rw-r--r--test/functional/helpers.lua39
2 files changed, 54 insertions, 14 deletions
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,