aboutsummaryrefslogtreecommitdiff
path: root/test/functional/helpers.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-12-15 06:40:55 +0100
committerGitHub <noreply@github.com>2016-12-15 06:40:55 +0100
commit02a9824438adb89eed8b0230068bb95bbf7ce97c (patch)
tree98e15d480351d39e90bb1c5f2102ee22d58da95b /test/functional/helpers.lua
parentf089d299e33e9f5d1a52aa6d3b9c1ea43bb2e51c (diff)
parentb29c5dd3848d3621dfbb00f8f940506cc1048fd1 (diff)
downloadrneovim-02a9824438adb89eed8b0230068bb95bbf7ce97c.tar.gz
rneovim-02a9824438adb89eed8b0230068bb95bbf7ce97c.tar.bz2
rneovim-02a9824438adb89eed8b0230068bb95bbf7ce97c.zip
Merge #5772 from justinmk/fixsegfault
eval.c: set_selfdict(): Fix invalid memory access.
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r--test/functional/helpers.lua26
1 files changed, 17 insertions, 9 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index d1ab02f361..f3332cff4f 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -1,4 +1,5 @@
require('coxpcall')
+local luv = require('luv')
local lfs = require('lfs')
local global_helpers = require('test.helpers')
@@ -243,17 +244,24 @@ local function connect(file_or_address)
return Session.new(stream)
end
--- Calls fn() until it returns without error, up to `max` times.
-local function retry(fn, max)
- local retries = max and (max - 1) or 2
- for _ = 1, retries do
- local success = pcall(fn)
- if success then
- return
+-- Calls fn() until it succeeds, up to `max` times or until `max_ms`
+-- milliseconds have passed.
+local function retry(max, max_ms, fn)
+ local tries = 1
+ local timeout = (max_ms and max_ms > 0) and max_ms or 10000
+ local start_time = luv.now()
+ while true do
+ local status, result = pcall(fn)
+ if status then
+ return result
+ end
+ if (max and tries >= max) or (luv.now() - start_time > timeout) then
+ break
end
+ tries = tries + 1
end
- -- pcall() is not used for the final attempt so failure can bubble up.
- fn()
+ -- Do not use pcall() for the final attempt, let the failure bubble up.
+ return fn()
end
local function clear(...)