mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
tests: load-adjust timer tests (functionaltest)
This commit is contained in:
parent
0afd452ef1
commit
f2e996b991
@ -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 source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run
|
||||||
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
|
local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs
|
||||||
local curbufmeths = helpers.curbufmeths
|
local curbufmeths = helpers.curbufmeths
|
||||||
|
local load_adjust = helpers.load_adjust
|
||||||
|
|
||||||
describe('timers', function()
|
describe('timers', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@ -19,14 +20,14 @@ describe('timers', function()
|
|||||||
it('works one-shot', function()
|
it('works one-shot', function()
|
||||||
command("call timer_start(50, 'MyHandler')")
|
command("call timer_start(50, 'MyHandler')")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 200)
|
run(nil, nil, nil, load_adjust(200))
|
||||||
eq(1,eval("g:val"))
|
eq(1,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works one-shot when repeat=0', function()
|
it('works one-shot when repeat=0', function()
|
||||||
command("call timer_start(50, 'MyHandler', {'repeat': 0})")
|
command("call timer_start(50, 'MyHandler', {'repeat': 0})")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 200)
|
run(nil, nil, nil, load_adjust(200))
|
||||||
eq(1,eval("g:val"))
|
eq(1,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ describe('timers', function()
|
|||||||
it('works with repeat two', function()
|
it('works with repeat two', function()
|
||||||
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
eq(2,eval("g:val"))
|
eq(2,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -42,14 +43,14 @@ describe('timers', function()
|
|||||||
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
command("call timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||||
nvim_async("command", "sleep 10")
|
nvim_async("command", "sleep 10")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
eq(2,eval("g:val"))
|
eq(2,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with zero timeout', function()
|
it('works with zero timeout', function()
|
||||||
-- timer_start does still not invoke the callback immediately
|
-- timer_start does still not invoke the callback immediately
|
||||||
eq(0,eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]"))
|
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"))
|
eq(1000,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -58,18 +59,18 @@ describe('timers', function()
|
|||||||
-- this also tests that remote requests works during sleep
|
-- this also tests that remote requests works during sleep
|
||||||
eval("timer_start(50, 'MyHandler', {'repeat': 2})")
|
eval("timer_start(50, 'MyHandler', {'repeat': 2})")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
eq(2,eval("g:val"))
|
eq(2,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('are paused when event processing is disabled', function()
|
it('are paused when event processing is disabled', function()
|
||||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
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")
|
local count = eval("g:val")
|
||||||
-- shows two line error message and thus invokes the return prompt.
|
-- 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.
|
-- if we start to allow event processing here, we need to change this test.
|
||||||
feed(':throw "fatal error"<CR>')
|
feed(':throw "fatal error"<CR>')
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
feed("<cr>")
|
feed("<cr>")
|
||||||
local diff = eval("g:val") - count
|
local diff = eval("g:val") - count
|
||||||
assert(0 <= diff and diff <= 4,
|
assert(0 <= diff and diff <= 4,
|
||||||
@ -79,7 +80,7 @@ describe('timers', function()
|
|||||||
it('are triggered in blocking getchar() call', function()
|
it('are triggered in blocking getchar() call', function()
|
||||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||||
nvim_async("command", "let g:c = getchar()")
|
nvim_async("command", "let g:c = getchar()")
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
feed("c")
|
feed("c")
|
||||||
local count = eval("g:val")
|
local count = eval("g:val")
|
||||||
assert(count >= 3, 'expected count >= 3, got: '..tostring(count))
|
assert(count >= 3, 'expected count >= 3, got: '..tostring(count))
|
||||||
@ -137,10 +138,10 @@ describe('timers', function()
|
|||||||
it('can be stopped', function()
|
it('can be stopped', function()
|
||||||
local t = eval("timer_start(50, 'MyHandler', {'repeat': -1})")
|
local t = eval("timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
funcs.timer_stop(t)
|
funcs.timer_stop(t)
|
||||||
local count = eval("g:val")
|
local count = eval("g:val")
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
local count2 = eval("g:val")
|
local count2 = eval("g:val")
|
||||||
-- when count is eval:ed after timer_stop this should be non-racy
|
-- when count is eval:ed after timer_stop this should be non-racy
|
||||||
eq(count, count2)
|
eq(count, count2)
|
||||||
@ -161,7 +162,7 @@ describe('timers', function()
|
|||||||
]])
|
]])
|
||||||
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
command("call timer_start(50, 'MyHandler', {'repeat': -1})")
|
||||||
eq(0,eval("g:val"))
|
eq(0,eval("g:val"))
|
||||||
run(nil, nil, nil, 300)
|
run(nil, nil, nil, load_adjust(300))
|
||||||
eq(3,eval("g:val"))
|
eq(3,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ describe('timers', function()
|
|||||||
]])
|
]])
|
||||||
command("call timer_start(20, 'MyHandler', {'repeat': 3})")
|
command("call timer_start(20, 'MyHandler', {'repeat': 3})")
|
||||||
command("call timer_start(40, 'MyHandler2', {'repeat': 2})")
|
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(3,eval("g:val"))
|
||||||
eq(2,eval("g:val2"))
|
eq(2,eval("g:val2"))
|
||||||
end)
|
end)
|
||||||
@ -189,7 +190,7 @@ describe('timers', function()
|
|||||||
endfunc
|
endfunc
|
||||||
]])
|
]])
|
||||||
command("call timer_start(5, 'MyHandler', {'repeat': 1})")
|
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"))
|
eq(1,eval("g:val"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -679,6 +679,44 @@ local function alter_slashes(obj)
|
|||||||
end
|
end
|
||||||
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 = {
|
local module = {
|
||||||
NIL = mpack.NIL,
|
NIL = mpack.NIL,
|
||||||
alter_slashes = alter_slashes,
|
alter_slashes = alter_slashes,
|
||||||
@ -720,6 +758,7 @@ local module = {
|
|||||||
meths = meths,
|
meths = meths,
|
||||||
missing_provider = missing_provider,
|
missing_provider = missing_provider,
|
||||||
mkdir = lfs.mkdir,
|
mkdir = lfs.mkdir,
|
||||||
|
load_adjust = load_adjust,
|
||||||
near = near,
|
near = near,
|
||||||
neq = neq,
|
neq = neq,
|
||||||
new_pipename = new_pipename,
|
new_pipename = new_pipename,
|
||||||
|
Loading…
Reference in New Issue
Block a user