Skip to content

Commit

Permalink
test: retry cluster init on fail
Browse files Browse the repository at this point in the history
Sometimes cluster fails to bootstrap in tests. The reasons are yet
unknown and likely unrelated to crud or maybe even crud tests setup.

After this patch, in case cluster preparation had failed for a test,
we retry to create a cluster up t three times.

Part of #432
  • Loading branch information
DifferentialOrange committed Apr 11, 2024
1 parent 99315a5 commit 6a980e8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
57 changes: 43 additions & 14 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -902,30 +902,59 @@ 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 = 2
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')

if opts.wait_crud_is_ready then
local ok, err = pcall(helpers.wait_crud_is_ready_on_cluster, g)
if ok then
break
end

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

if current_attempt == opts.retries then
error(err)
end
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

0 comments on commit 6a980e8

Please sign in to comment.