Skip to content

Commit

Permalink
test: wait until cluster leaders are rw
Browse files Browse the repository at this point in the history
Tarantool 3.0 instances start in ro mode. It is possible that masters
are not available for write requests right after test case has been
started.

Cartridge servers run only on Tarantool 1.x and 2.x, so they are
expected to work fine without additional changes: Cartridge helpers
checks are sophisticated enough.

Part of #412
Part of #415
  • Loading branch information
DifferentialOrange committed Apr 16, 2024
1 parent 4c8e093 commit 0c109f9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
15 changes: 14 additions & 1 deletion test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ function helpers.get_results_list(results_map)
return results_list
end

function helpers.box_cfg()
function helpers.box_cfg(opts)
opts = opts or {}

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

if type(box.cfg) ~= 'function' then
return
end
Expand All @@ -127,6 +133,13 @@ function helpers.box_cfg()
wal_mode = 'none',
})
fio.rmtree(tempdir)

if opts.wait_rw then
t.helpers.retrying(
{timeout = 3, delay = 0.1},
t.assert_equals, box.info.ro, false
)
end
end

function helpers.insert_objects(g, space_name, objects)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/select_readview_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2308,6 +2308,8 @@ pgroup.test_stop_select = function(g)
g.cluster:server('s2-master'):start()

if g.params.backend == helpers.backend.VSHARD then
g.cluster:server('s2-master'):wait_for_rw()

local bootstrap_key
if type(g.params.backend_cfg) == 'table'
and g.params.backend_cfg.identification_mode == 'name_as_key' then
Expand Down
12 changes: 6 additions & 6 deletions test/unit/sharding_metadata_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ g.before_each(function()
{name = 'sharding_func_body', type = 'string', is_nullable = true},
}

if type(box.cfg) ~= 'table' then
helpers.box_cfg()
end
helpers.box_cfg()

-- Create a space _ddl_sharding_key with a tuple that
-- contains a space name and it's sharding key.
box.schema.space.create('_ddl_sharding_key', {
format = sharding_key_format,
if_not_exists = true,
})
box.space._ddl_sharding_key:create_index('pk')
box.space._ddl_sharding_key:create_index('pk', {if_not_exists = true})

-- Create a space _ddl_sharding_func with a tuple that
-- contains a space name and it's sharding func name/body.
box.schema.space.create('_ddl_sharding_func', {
format = sharding_func_format,
if_not_exists = true,
})
box.space._ddl_sharding_func:create_index('pk')
box.space._ddl_sharding_func:create_index('pk', {if_not_exists = true})

box.schema.space.create('fetch_on_storage')
box.schema.space.create('fetch_on_storage', {if_not_exists = true})
end)

-- Since Tarantool 3.0 triggers still live after a space drop. To properly
Expand Down
10 changes: 10 additions & 0 deletions test/vshard_helpers/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ function Server:wait_for_readiness()
end)
end

function Server:wait_for_rw()
return wait_cond('rw', self, function()
local ok, is_ready = pcall(function()
self:connect_net_box()
return self.net_box:eval('return box.info.ro') == false
end)
return ok and is_ready
end)
end

function Server:wait_election_leader()
-- Include read-only property too because if an instance is a leader, it
-- does not mean it finished the synchro queue ownership transition. It is
Expand Down
1 change: 1 addition & 0 deletions test/vshard_helpers/vtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ local function cluster_new(g, cfg)

for _, master in pairs(masters) do
master:wait_for_readiness()
master:wait_for_rw()
master:exec(function(cfg)
-- Logged in as guest with 'super' access rights. Yet 'super' is not
-- enough to grant 'replication' privilege. The simplest way - login
Expand Down

0 comments on commit 0c109f9

Please sign in to comment.