Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: retry cluster init on fail #433

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -902,30 +902,63 @@ function helpers.start_tarantool3_cluster(g, cfg)
end

function helpers.start_cluster(g, cartridge_cfg, vshard_cfg, tarantool3_cluster_cfg, opts)
checks('table', '?table', '?table', '?table', {wait_crud_is_ready = '?boolean'})
checks('table', '?table', '?table', '?table', {
wait_crud_is_ready = '?boolean',
backend = '?string',
retries = '?number',
})

opts = opts or {}

if opts.wait_crud_is_ready == nil then
opts.wait_crud_is_ready = true
end

if g.params.backend == helpers.backend.CARTRIDGE then
helpers.skip_cartridge_unsupported()

helpers.start_cartridge_cluster(g, cartridge_cfg)
elseif g.params.backend == helpers.backend.VSHARD then
helpers.start_vshard_cluster(g, vshard_cfg)
elseif g.params.backend == helpers.backend.CONFIG then
helpers.skip_if_tarantool3_crud_roles_unsupported()
if opts.backend == nil then
opts.backend = g.params.backend
end
assert(opts.backend ~= nil, 'Please, provide backend')

helpers.start_tarantool3_cluster(g, tarantool3_cluster_cfg)
local DEFAULT_RETRIES = 3
if opts.retries == nil then
opts.retries = DEFAULT_RETRIES
end

g.router = g.cluster:server('router')
assert(g.router ~= nil, 'router found')
local current_attempt = 0
while true do
current_attempt = current_attempt + 1

if opts.backend == helpers.backend.CARTRIDGE then
helpers.skip_cartridge_unsupported()

helpers.start_cartridge_cluster(g, cartridge_cfg)
elseif opts.backend == helpers.backend.VSHARD then
helpers.start_vshard_cluster(g, vshard_cfg)
elseif opts.backend == helpers.backend.CONFIG then
helpers.skip_if_tarantool3_crud_roles_unsupported()

if opts.wait_crud_is_ready then
helpers.wait_crud_is_ready_on_cluster(g)
helpers.start_tarantool3_cluster(g, tarantool3_cluster_cfg)
end

g.router = g.cluster:server('router')
assert(g.router ~= nil, 'router found')

local ok, err = false, nil -- luacheck: ignore
if opts.wait_crud_is_ready then
ok, err = pcall(helpers.wait_crud_is_ready_on_cluster, g, {backend = opts.backend})
else
ok = true
end

if ok then
break
end

helpers.stop_cluster(g.cluster, opts.backend)

if current_attempt == opts.retries then
error(err)
end
end
end

Expand Down
7 changes: 3 additions & 4 deletions test/integration/role_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ end)
g.before_each(function(cg)
-- Tests are rather dangerous and may break the cluster,
-- so it's safer to restart for each case.
helpers.start_tarantool3_cluster(cg, cg.template_cfg)
cg.router = cg.cluster:server('router')

helpers.wait_crud_is_ready_on_cluster(cg, {backend = helpers.backend.CONFIG})
helpers.start_cluster(cg, nil, nil, cg.template_cfg, {
backend = helpers.backend.CONFIG,
})
end)

g.after_each(function(cg)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/not_initialized_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pgroup.before_all(function(g)
cartridge_cfg_template,
vshard_cfg_template,
tarantool3_cluster_cfg_template,
{wait_crud_is_ready = false}
{wait_crud_is_ready = false, retries = 1}
)

g.router = g.cluster:server('router')
Expand Down
Loading