Skip to content

Commit

Permalink
error: introduce is_timeout
Browse files Browse the repository at this point in the history
It's needed to check, whether the error was a timeout or not in the
following commit. Let's move this function from vtest to error module.

Needed for #426

NO_DOC=internal
  • Loading branch information
Serpentian authored and Gerold103 committed Dec 19, 2023
1 parent 4c14eb4 commit 9d52e1e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
12 changes: 0 additions & 12 deletions test/luatest_helpers/vtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ local function replicaset_name_to_uuid(name)
return name_to_uuid(replicaset_name_to_uuid_map, name)
end

--
-- Timeout error can be a ClientError with ER_TIMEOUT code or a TimedOut error
-- which is ER_SYSTEM. They also have different messages. Same public APIs can
-- return both errors depending on core version and/or error cause. This func
-- helps not to care.
--
local function error_is_timeout(err)
return err.code == box.error.TIMEOUT or (err.code == box.error.PROC_LUA and
err.message == 'Timeout exceeded') or err.type == 'TimedOut'
end

local function clear_test_cfg_options(cfg)
cfg.test_user_grant_range = nil
end
Expand Down Expand Up @@ -848,7 +837,6 @@ end
local vardir = fio.abspath(os.getenv('VARDIR'))

return {
error_is_timeout = error_is_timeout,
config_new = config_new,
cluster_new = cluster_new,
cluster_cfg = cluster_cfg,
Expand Down
3 changes: 2 additions & 1 deletion test/replicaset-luatest/replicaset_3_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local fiber = require('fiber')
local t = require('luatest')
local vreplicaset = require('vshard.replicaset')
local vtest = require('test.luatest_helpers.vtest')
local verror = require('vshard.error')

local small_timeout_opts = {timeout = 0.05}
local timeout_opts = {timeout = vtest.wait_timeout}
Expand Down Expand Up @@ -176,7 +177,7 @@ test_group.test_map_call = function(g)
end, {uuid_c})
res, err = rs:map_call('test_sleep_c', {}, small_timeout_opts)
t.assert_not_equals(err, nil)
t.assert(vtest.error_is_timeout(err))
t.assert(verror.is_timeout(err))
t.assert_equals(res, nil)
res = vtest.cluster_exec_each(g, function()
_G.test_sleep_do = false
Expand Down
2 changes: 1 addition & 1 deletion test/storage-luatest/storage_1_1_1_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test_group.test_manual_bucket_send_doubled_buckets = function(g)
local bid = g.replica_1_a:exec(function(uuid)
local bid = _G.get_first_bucket()
local ok, err = ivshard.storage.bucket_send(bid, uuid)
ilt.assert(ivtest.error_is_timeout(err))
ilt.assert(iverror.is_timeout(err))
ilt.assert_not(ok, 'bucket_send not ok')
return bid
end, {uuid_2})
Expand Down
6 changes: 3 additions & 3 deletions test/unit-luatest/util_test.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local t = require('luatest')
local luuid = require('uuid')
local server = require('test.luatest_helpers.server')
local vtest = require('test.luatest_helpers.vtest')
local vutil = require('vshard.util')
local verror = require('vshard.error')
local net = require('net.box')

local test_group = t.group('util')
Expand Down Expand Up @@ -252,11 +252,11 @@ test_group.test_future_wait_timeout = function(g)

-- Default timeout error
local _, err = vutil.future_wait(f, 1e-6)
t.assert_equals(vtest.error_is_timeout(err), true)
t.assert_equals(verror.is_timeout(err), true)

-- Negative timeout should return timeout error too
_, err = vutil.future_wait(f, -1)
t.assert_equals(vtest.error_is_timeout(err), true)
t.assert_equals(verror.is_timeout(err), true)

stop_sleep()
-- Everything is all right, wait for result
Expand Down
12 changes: 12 additions & 0 deletions vshard/error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ local function make_timeout()
return make_error(box.error.new(box.error.TIMEOUT))
end

--
-- Timeout error can be a ClientError with ER_TIMEOUT code or a TimedOut error
-- which is ER_SYSTEM. They also have different messages. Same public APIs can
-- return both errors depending on core version and/or error cause. This func
-- helps not to care.
--
local function error_is_timeout(err)
return err.code == box.error.TIMEOUT or (err.code == box.error.PROC_LUA and
err.message == 'Timeout exceeded') or err.type == 'TimedOut'
end

return {
code = error_code,
box = box_error,
Expand All @@ -325,4 +336,5 @@ return {
from_string = from_string,
alert = make_alert,
timeout = make_timeout,
is_timeout = error_is_timeout,
}

0 comments on commit 9d52e1e

Please sign in to comment.