Skip to content

Commit

Permalink
test: drop meta from vtest.config_new()
Browse files Browse the repository at this point in the history
The test function used to return 2 values: config and its meta.
The meta could be used to retrieve certain sections of the config
by name, without knowing the automatically generated UUIDs.

The approach appeared to be too clumsy in the next patches. It
would be easier to get UUIDs from the instances like this patch
does.

Part of #325
  • Loading branch information
Gerold103 committed May 11, 2022
1 parent 4ce57e1 commit 9d1eec6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
16 changes: 16 additions & 0 deletions test/luatest_helpers/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ function Server:instance_uuid()
return uuid
end

function Server:replicaset_uuid()
-- Cache the value when found it first time.
if self.replicaset_uuid_value then
return self.replicaset_uuid_value
end
local uuid = self:exec(function() return box.info.cluster.uuid end)
if uuid == nil then
-- Probably didn't bootstrap yet. Listen starts before replicaset UUID
-- is assigned.
return nil
end
self.replicaset_uuid_value = uuid
return uuid
end

-- TODO: Add the 'wait_for_readiness' parameter for the restart()
-- method.

Expand Down Expand Up @@ -192,6 +207,7 @@ function Server:cleanup()
end
self.instance_id_value = nil
self.instance_uuid_value = nil
self.replicaset_uuid_value = nil
end

function Server:drop()
Expand Down
6 changes: 1 addition & 5 deletions test/luatest_helpers/vtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ end
local function config_new(templ)
local res = table.deepcopy(templ)
local sharding = {}
local meta = {replicasets = {}}
res.sharding = sharding
for i, replicaset_templ in pairs(templ.sharding) do
local replicaset_uuid = uuid_next()
meta.replicasets[i] = {
uuid = replicaset_uuid
}
local replicas = {}
local replicaset = table.deepcopy(replicaset_templ)
replicaset.replicas = replicas
Expand All @@ -40,7 +36,7 @@ local function config_new(templ)
end
sharding[replicaset_uuid] = replicaset
end
return res, meta
return res
end

--
Expand Down
12 changes: 7 additions & 5 deletions test/router-luatest/router_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local vutil = require('vshard.util')
local wait_timeout = 120

local g = t.group('router')
local cluster_cfg, cfg_meta = vtest.config_new({
local cluster_cfg = vtest.config_new({
sharding = {
{
replicas = {
Expand Down Expand Up @@ -206,9 +206,11 @@ g.test_map_callrw_raw = function(g)
err = err,
}
end, {wait_timeout})
local rs1_uuid = g.replica_1_a:replicaset_uuid()
local rs2_uuid = g.replica_2_a:replicaset_uuid()
local expected = {
[cfg_meta.replicasets[1].uuid] = {{1, 3}},
[cfg_meta.replicasets[2].uuid] = {{2, 3}},
[rs1_uuid] = {{1, 3}},
[rs2_uuid] = {{2, 3}},
}
t.assert_equals(res.val, expected, 'map callrw success')
t.assert_equals(res.map_type, 'userdata', 'values are msgpacks')
Expand All @@ -226,7 +228,7 @@ g.test_map_callrw_raw = function(g)
return_raw = true})
end, {wait_timeout})
expected = {
[cfg_meta.replicasets[1].uuid] = {{1}},
[rs1_uuid] = {{1}},
}
t.assert_equals(res, expected, 'map callrw without one value success')
--
Expand All @@ -248,7 +250,7 @@ g.test_map_callrw_raw = function(g)
type = 'ClientError',
message = 'map_err'
}, 'error object')
t.assert_equals(err_uuid, cfg_meta.replicasets[2].uuid, 'error uuid')
t.assert_equals(err_uuid, rs2_uuid, 'error uuid')
--
-- Cleanup.
--
Expand Down

0 comments on commit 9d1eec6

Please sign in to comment.