Skip to content

Commit c8f56cc

Browse files
Serpentiansergepetrenko
authored andcommitted
test: move test_named_config_identification to a separate file
The problem with this test is that it sets names, which is not easily revertable. Consequently, if it's located in a big test suite, like storage_1_1, we cannot rely in other tests either on the presence of the names or on their absence, which is very unconvenient. Let's move the test in the separate file, so that in storage_1_1 we always know, that the names are not set. NO_DOC=test
1 parent 86b3bf4 commit c8f56cc

File tree

2 files changed

+138
-90
lines changed

2 files changed

+138
-90
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
local t = require('luatest')
2+
local vtest = require('test.luatest_helpers.vtest')
3+
local vutil = require('vshard.util')
4+
5+
local group_config = {{engine = 'memtx'}, {engine = 'vinyl'}}
6+
7+
if vutil.feature.memtx_mvcc then
8+
table.insert(group_config, {
9+
engine = 'memtx', memtx_use_mvcc_engine = true
10+
})
11+
table.insert(group_config, {
12+
engine = 'vinyl', memtx_use_mvcc_engine = true
13+
})
14+
end
15+
16+
local test_group = t.group('storage', group_config)
17+
18+
local cfg_template = {
19+
sharding = {
20+
{
21+
replicas = {
22+
replica_1_a = {
23+
master = true,
24+
},
25+
},
26+
},
27+
{
28+
replicas = {
29+
replica_2_a = {
30+
master = true,
31+
},
32+
},
33+
},
34+
},
35+
bucket_count = 10,
36+
replication_timeout = 0.1,
37+
}
38+
local global_cfg
39+
40+
test_group.before_all(function(g)
41+
t.run_only_if(vutil.feature.persistent_names)
42+
cfg_template.memtx_use_mvcc_engine = g.params.memtx_use_mvcc_engine
43+
global_cfg = vtest.config_new(cfg_template)
44+
45+
vtest.cluster_new(g, global_cfg)
46+
vtest.cluster_bootstrap(g, global_cfg)
47+
vtest.cluster_rebalancer_disable(g)
48+
end)
49+
50+
test_group.after_all(function(g)
51+
g.cluster:drop()
52+
end)
53+
54+
test_group.test_named_config_identification = function(g)
55+
local new_cfg_template = table.deepcopy(cfg_template)
56+
new_cfg_template.identification_mode = 'name_as_key'
57+
new_cfg_template.sharding['replicaset_1'] = new_cfg_template.sharding[1]
58+
new_cfg_template.sharding['replicaset_2'] = new_cfg_template.sharding[2]
59+
new_cfg_template.sharding[1] = nil
60+
new_cfg_template.sharding[2] = nil
61+
local new_global_cfg = vtest.config_new(new_cfg_template)
62+
63+
-- Attempt to configure with named config without name set causes error.
64+
g.replica_1_a:exec(function(cfg)
65+
-- Name is not shown in info, when uuid identification is used.
66+
local info = ivshard.storage.info()
67+
local rs = info.replicasets[ivutil.replicaset_uuid()]
68+
ilt.assert_equals(rs.name, nil)
69+
ilt.assert_equals(rs.master.name, nil)
70+
ilt.assert_equals(info.identification_mode, 'uuid_as_key')
71+
ilt.assert_error_msg_contains('Instance name mismatch',
72+
ivshard.storage.cfg, cfg, 'replica_1_a')
73+
end, {new_global_cfg})
74+
75+
-- Set names on all replicas.
76+
g.replica_1_a:exec(function()
77+
box.cfg{instance_name = 'replica_1_a', replicaset_name = 'replicaset_1'}
78+
end)
79+
g.replica_2_a:exec(function()
80+
box.cfg{instance_name = 'replica_2_a', replicaset_name = 'replicaset_2'}
81+
end)
82+
83+
-- Check, that UUIDs are validated, when named config is used.
84+
local rs_1_cfg = new_global_cfg.sharding.replicaset_1
85+
local replica_1_a_cfg = rs_1_cfg.replicas.replica_1_a
86+
replica_1_a_cfg.uuid = g.replica_2_a:instance_uuid()
87+
g.replica_1_a:exec(function(cfg)
88+
ilt.assert_error_msg_contains('Instance UUID mismatch',
89+
ivshard.storage.cfg, cfg, 'replica_1_a')
90+
end, {new_global_cfg})
91+
-- The correct UUID should be OK.
92+
replica_1_a_cfg.uuid = g.replica_1_a:instance_uuid()
93+
94+
-- Now the config can be finally applied.
95+
vtest.cluster_cfg(g, new_global_cfg)
96+
97+
-- Test, that sending by name works properly
98+
local rs_name_2 = g.replica_2_a:replicaset_name()
99+
t.assert_equals(rs_name_2, 'replicaset_2')
100+
g.replica_1_a:exec(function(name)
101+
-- Name is shown, when name identification is used.
102+
local info = ivshard.storage.info()
103+
local rs = info.replicasets[box.info.replicaset.name]
104+
ilt.assert_equals(rs.name, box.info.replicaset.name)
105+
ilt.assert_equals(rs.uuid, nil)
106+
ilt.assert_equals(rs.master.name, box.info.name)
107+
ilt.assert_equals(info.identification_mode, 'name_as_key')
108+
109+
local bid = _G.get_first_bucket()
110+
local ok, err = ivshard.storage.bucket_send(
111+
bid, name, {timeout = _G.iwait_timeout})
112+
ilt.assert_equals(err, nil)
113+
ilt.assert(ok)
114+
end, {rs_name_2})
115+
116+
-- Test, that rebalancer is also ok.
117+
vtest.cluster_rebalancer_enable(g)
118+
g.replica_1_a:exec(function()
119+
local internal = ivshard.storage.internal
120+
ivtest.service_wait_for_new_ok(internal.rebalancer_service,
121+
{on_yield = ivshard.storage.rebalancer_wakeup})
122+
123+
-- Cleanup
124+
_G.bucket_recovery_wait()
125+
_G.bucket_gc_wait()
126+
ilt.assert_equals(box.space._bucket:count(), 5)
127+
end)
128+
129+
g.replica_2_a:exec(function()
130+
_G.bucket_recovery_wait()
131+
_G.bucket_gc_wait()
132+
ilt.assert_equals(box.space._bucket:count(), 5)
133+
end)
134+
135+
vtest.cluster_rebalancer_disable(g)
136+
-- Back to UUID identification.
137+
vtest.cluster_cfg(g, global_cfg)
138+
end

test/storage-luatest/storage_1_1_test.lua

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -531,93 +531,3 @@ test_group.test_noactivity_timeout_for_explicit_master = function(g)
531531
_G.bucket_gc_wait()
532532
end, {g.replica_1_a:replicaset_uuid(), bid})
533533
end
534-
535-
test_group.test_named_config_identification = function(g)
536-
t.run_only_if(vutil.feature.persistent_names)
537-
local new_cfg_template = table.deepcopy(cfg_template)
538-
new_cfg_template.identification_mode = 'name_as_key'
539-
new_cfg_template.sharding['replicaset_1'] = new_cfg_template.sharding[1]
540-
new_cfg_template.sharding['replicaset_2'] = new_cfg_template.sharding[2]
541-
new_cfg_template.sharding[1] = nil
542-
new_cfg_template.sharding[2] = nil
543-
local new_global_cfg = vtest.config_new(new_cfg_template)
544-
545-
-- Attempt to configure with named config without name set causes error.
546-
g.replica_1_a:exec(function(cfg)
547-
-- Name is not shown in info, when uuid identification is used.
548-
local info = ivshard.storage.info()
549-
local rs = info.replicasets[ivutil.replicaset_uuid()]
550-
ilt.assert_equals(rs.name, nil)
551-
ilt.assert_equals(rs.master.name, nil)
552-
ilt.assert_equals(info.identification_mode, 'uuid_as_key')
553-
ilt.assert_error_msg_contains('Instance name mismatch',
554-
ivshard.storage.cfg, cfg, 'replica_1_a')
555-
end, {new_global_cfg})
556-
557-
-- Set names on all replicas.
558-
g.replica_1_a:exec(function()
559-
box.cfg{instance_name = 'replica_1_a', replicaset_name = 'replicaset_1'}
560-
end)
561-
g.replica_2_a:exec(function()
562-
box.cfg{instance_name = 'replica_2_a', replicaset_name = 'replicaset_2'}
563-
end)
564-
565-
-- Check, that UUIDs are validated, when named config is used.
566-
local rs_1_cfg = new_global_cfg.sharding.replicaset_1
567-
local replica_1_a_cfg = rs_1_cfg.replicas.replica_1_a
568-
replica_1_a_cfg.uuid = g.replica_2_a:instance_uuid()
569-
g.replica_1_a:exec(function(cfg)
570-
ilt.assert_error_msg_contains('Instance UUID mismatch',
571-
ivshard.storage.cfg, cfg, 'replica_1_a')
572-
end, {new_global_cfg})
573-
-- The correct UUID should be OK.
574-
replica_1_a_cfg.uuid = g.replica_1_a:instance_uuid()
575-
576-
-- Now the config can be finally applied.
577-
vtest.cluster_cfg(g, new_global_cfg)
578-
579-
-- Test, that sending by name works properly
580-
local rs_name_2 = g.replica_2_a:replicaset_name()
581-
t.assert_equals(rs_name_2, 'replicaset_2')
582-
local bid = g.replica_1_a:exec(function(name)
583-
-- Name is shown, when name identification is used.
584-
local info = ivshard.storage.info()
585-
local rs = info.replicasets[box.info.replicaset.name]
586-
ilt.assert_equals(rs.name, box.info.replicaset.name)
587-
ilt.assert_equals(rs.uuid, nil)
588-
ilt.assert_equals(rs.master.name, box.info.name)
589-
ilt.assert_equals(info.identification_mode, 'name_as_key')
590-
591-
local bid = _G.get_first_bucket()
592-
local ok, err = ivshard.storage.bucket_send(
593-
bid, name, {timeout = _G.iwait_timeout})
594-
ilt.assert_equals(err, nil)
595-
ilt.assert(ok)
596-
return bid
597-
end, {rs_name_2})
598-
599-
-- Test, that rebalancer is also ok.
600-
vtest.cluster_rebalancer_enable(g)
601-
g.replica_1_a:exec(function(bid)
602-
local internal = ivshard.storage.internal
603-
ivtest.service_wait_for_new_ok(internal.rebalancer_service,
604-
{on_yield = ivshard.storage.rebalancer_wakeup})
605-
606-
-- Cleanup
607-
_G.bucket_recovery_wait()
608-
_G.bucket_gc_wait()
609-
ilt.assert_equals(ivshard.storage.buckets_info()[bid], nil)
610-
end, {bid})
611-
612-
g.replica_2_a:exec(function(bid)
613-
_G.bucket_recovery_wait()
614-
_G.bucket_gc_wait()
615-
local buckets_info = ivshard.storage.buckets_info()
616-
ilt.assert_not_equals(buckets_info[bid], nil)
617-
ilt.assert_equals(buckets_info[bid].status, 'active')
618-
end, {bid})
619-
620-
vtest.cluster_rebalancer_disable(g)
621-
-- Back to UUID identification.
622-
vtest.cluster_cfg(g, global_cfg)
623-
end

0 commit comments

Comments
 (0)