Skip to content

Commit c31d08d

Browse files
committed
test: add test_named_replicaset_alerts_when_replica_disconnects
This test checks scenario when replica disconnects from replicaset in named vshard config. In this situation two alerts should be thrown: `UNREACHABLE_REPLICA` and `UNREACHABLE_REPLICASET`. It is necessary to add this test in order to reduce untested places in the codebase. Also a function `info_assert_alert` is removed from `router_2_2_test` since there is a more appropriate function in `asserts` module. Follow-up tarantool#493 NO_DOC=test
1 parent efa0be0 commit c31d08d

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

test/luatest_helpers/asserts.lua

+9
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ function asserts:assert_server_no_alerts(server)
4646
end)
4747
end
4848

49+
function asserts:info_assert_alert(alerts, alert_name)
50+
for _, alert in pairs(alerts) do
51+
if alert[1] == alert_name then
52+
return alert
53+
end
54+
end
55+
t.fail(('There is no %s in alerts').format(alert_name))
56+
end
57+
4958
return asserts

test/router-luatest/router_2_2_test.lua

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local vtest = require('test.luatest_helpers.vtest')
33
local vutil = require('vshard.util')
44
local vconsts = require('vshard.consts')
55
local vserver = require('test.luatest_helpers.server')
6+
local asserts = require('test.luatest_helpers.asserts')
67

78
local g = t.group('router')
89
local cfg_template = {
@@ -1044,14 +1045,6 @@ g.test_failed_calls_affect_priority = function()
10441045
vtest.router_cfg(g.router, global_cfg)
10451046
end
10461047

1047-
local function info_find_alert(alerts, alert_name)
1048-
for _, v in pairs(alerts) do
1049-
if v[1] == alert_name then
1050-
return v
1051-
end
1052-
end
1053-
end
1054-
10551048
--
10561049
-- gh-474: error during alert construction
10571050
--
@@ -1069,7 +1062,7 @@ g.test_info_with_named_identification = function()
10691062
ilt.assert(ok, 'no error')
10701063
return result.alerts
10711064
end)
1072-
t.assert(info_find_alert(alerts, 'MISSING_MASTER'),
1065+
t.assert(asserts:info_assert_alert(alerts, 'MISSING_MASTER'),
10731066
'MISSING_MASTER alert is constructed')
10741067

10751068
--
@@ -1085,7 +1078,7 @@ g.test_info_with_named_identification = function()
10851078
ilt.assert(ok, 'no error')
10861079
return result.alerts
10871080
end)
1088-
local alert = info_find_alert(alerts, 'UNREACHABLE_MASTER')
1081+
local alert = asserts:info_assert_alert(alerts, 'UNREACHABLE_MASTER')
10891082
t.assert(alert, 'UNREACHABLE_MASTER alert is constructed')
10901083
t.assert_not_str_contains(alert[2], 'replicaset nil',
10911084
'alert contains valid replicaset id')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
local t = require('luatest')
2+
local vtest = require('test.luatest_helpers.vtest')
3+
local vutil = require('vshard.util')
4+
local asserts = require('test.luatest_helpers.asserts')
5+
6+
local test_group = t.group('storage')
7+
8+
local cfg_template = {
9+
sharding = {
10+
repliacset_1 = {
11+
replicas = {
12+
replica_1_a = {
13+
master = true
14+
},
15+
replica_1_b = {},
16+
},
17+
},
18+
},
19+
bucket_count = 20,
20+
identification_mode = 'name_as_key'
21+
}
22+
23+
local global_cfg
24+
25+
test_group.before_all(function(g)
26+
t.run_only_if(vutil.feature.persistent_names)
27+
global_cfg = vtest.config_new(cfg_template)
28+
29+
vtest.cluster_new(g, global_cfg)
30+
vtest.cluster_bootstrap(g, global_cfg)
31+
vtest.cluster_wait_vclock_all(g)
32+
vtest.cluster_rebalancer_disable(g)
33+
end)
34+
35+
test_group.after_all(function(g)
36+
g.cluster:drop()
37+
end)
38+
39+
test_group.test_named_replicaset_alerts_when_replica_disconnects = function(g)
40+
g.replica_1_b:stop()
41+
local alerts = g.replica_1_a:exec(function()
42+
return ivshard.storage.info().alerts
43+
end)
44+
asserts:info_assert_alert(alerts, 'UNREACHABLE_REPLICA')
45+
asserts:info_assert_alert(alerts, 'UNREACHABLE_REPLICASET')
46+
g.replica_1_b:start()
47+
end

0 commit comments

Comments
 (0)