Skip to content

Commit

Permalink
test: make vtest.config_new() return one table
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 can be used to retrieve certain sections of the config by
name, without knowing the automatically generated UUIDs.

The approach with 2 values return appeared to be too clumsy in the
next patches. It would be easier to operate on a single value
which contains meta and cfg in it.

Part of #325
  • Loading branch information
Gerold103 committed May 9, 2022
1 parent 804410f commit 4098f67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 10 additions & 7 deletions test/luatest_helpers/vtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ end
-- anything volatile such as URIs, UUIDs - these are installed at runtime.
--
local function config_new(templ)
local res = table.deepcopy(templ)
local sharding = {}
local meta = {replicasets = {}}
res.sharding = sharding
local cfg = table.deepcopy(templ)
local cfg_sharding = {}
local meta_sharding = {}
local meta = {sharding = meta_sharding}
cfg.sharding = cfg_sharding
for i, replicaset_templ in pairs(templ.sharding) do
local replicaset_uuid = uuid_next()
meta.replicasets[i] = {
meta_sharding[i] = {
uuid = replicaset_uuid
}
local replicas = {}
Expand All @@ -38,15 +39,16 @@ local function config_new(templ)
replica.uri = 'storage:storage@'..helpers.instance_uri(replica_name)
replicas[replica_uuid] = replica
end
sharding[replicaset_uuid] = replicaset
cfg_sharding[replicaset_uuid] = replicaset
end
return res, meta
return {value = cfg, meta = meta}
end

--
-- Build new cluster by a given config.
--
local function storage_new(g, cfg)
cfg = cfg.value
if not g.cluster then
g.cluster = cluster:new({})
end
Expand Down Expand Up @@ -117,6 +119,7 @@ end
-- Create a new router in the cluster.
--
local function router_new(g, name, cfg)
cfg = cfg.value
if not g.cluster then
g.cluster = cluster:new({})
end
Expand Down
11 changes: 6 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,10 @@ g.test_map_callrw_raw = function(g)
err = err,
}
end, {wait_timeout})
local cfg_meta = cluster_cfg.meta
local expected = {
[cfg_meta.replicasets[1].uuid] = {{1, 3}},
[cfg_meta.replicasets[2].uuid] = {{2, 3}},
[cfg_meta.sharding[1].uuid] = {{1, 3}},
[cfg_meta.sharding[2].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 +227,7 @@ g.test_map_callrw_raw = function(g)
return_raw = true})
end, {wait_timeout})
expected = {
[cfg_meta.replicasets[1].uuid] = {{1}},
[cfg_meta.sharding[1].uuid] = {{1}},
}
t.assert_equals(res, expected, 'map callrw without one value success')
--
Expand All @@ -248,7 +249,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, cfg_meta.sharding[2].uuid, 'error uuid')
--
-- Cleanup.
--
Expand Down

0 comments on commit 4098f67

Please sign in to comment.