From 0c109f9fbf9205c6eef19a799940eef09ff2343f Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Mon, 22 Jan 2024 18:18:56 +0300 Subject: [PATCH] test: wait until cluster leaders are rw 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 --- test/helper.lua | 15 ++++++++++++++- test/integration/select_readview_test.lua | 2 ++ test/unit/sharding_metadata_test.lua | 12 ++++++------ test/vshard_helpers/server.lua | 10 ++++++++++ test/vshard_helpers/vtest.lua | 1 + 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/test/helper.lua b/test/helper.lua index 9195226d..809e97d6 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -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 @@ -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) diff --git a/test/integration/select_readview_test.lua b/test/integration/select_readview_test.lua index d17458ce..04231879 100644 --- a/test/integration/select_readview_test.lua +++ b/test/integration/select_readview_test.lua @@ -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 diff --git a/test/unit/sharding_metadata_test.lua b/test/unit/sharding_metadata_test.lua index be2ce2a3..d18ecb3a 100644 --- a/test/unit/sharding_metadata_test.lua +++ b/test/unit/sharding_metadata_test.lua @@ -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 diff --git a/test/vshard_helpers/server.lua b/test/vshard_helpers/server.lua index 6ed2448f..1b504f16 100644 --- a/test/vshard_helpers/server.lua +++ b/test/vshard_helpers/server.lua @@ -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 diff --git a/test/vshard_helpers/vtest.lua b/test/vshard_helpers/vtest.lua index 70236b97..6bc5a536 100644 --- a/test/vshard_helpers/vtest.lua +++ b/test/vshard_helpers/vtest.lua @@ -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