Skip to content

Commit 3dd1c6f

Browse files
Test stats on runtime schema create/drop
Add several test cases to check stats module behavior in case of creating new spaces or dropping ones in runtime. Follows up #224
1 parent 72dd358 commit 3dd1c6f

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/integration/stats_test.lua

+73
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local helpers = require('test.helper')
1616
local space_id = 542
1717
local space_name = 'customers'
1818
local unknown_space_name = 'non_existing_space'
19+
local new_space_name = 'newspace'
1920

2021
local function before_all(g)
2122
g.cluster = helpers.Cluster:new({
@@ -60,6 +61,7 @@ local function before_each(g)
6061
g.router:eval("crud = require('crud')")
6162
enable_stats(g)
6263
helpers.truncate_space_on_cluster(g.cluster, space_name)
64+
helpers.drop_space_on_cluster(g.cluster, new_space_name)
6365
end
6466

6567
local function get_metrics(g)
@@ -988,3 +990,74 @@ group_metrics.test_stats_changed_in_metrics_registry_after_module_reload = funct
988990

989991
check_updated_per_call(g)
990992
end
993+
994+
995+
local function create_new_space(g)
996+
helpers.call_on_storages(g.cluster, function(server)
997+
server.net_box:eval([[
998+
local space_name = ...
999+
if not box.cfg.read_only then
1000+
local sp = box.schema.space.create(space_name, { format = {
1001+
{name = 'id', type = 'unsigned'},
1002+
{name = 'bucket_id', type = 'unsigned'},
1003+
}})
1004+
1005+
sp:create_index('pk', {
1006+
parts = { {field = 'id'} },
1007+
})
1008+
1009+
sp:create_index('bucket_id', {
1010+
parts = { {field = 'bucket_id'} },
1011+
unique = false,
1012+
})
1013+
end
1014+
]], { new_space_name })
1015+
end)
1016+
end
1017+
1018+
pgroup.test_spaces_created_in_runtime_supported_with_stats = function(g)
1019+
local op = 'insert'
1020+
local stats_before = get_stats(g, new_space_name)
1021+
local op_before = get_before_stats(stats_before, op)
1022+
1023+
create_new_space(g)
1024+
1025+
local _, err = g.router:call('crud.insert', { new_space_name, { 1, box.NULL }})
1026+
t.assert_equals(err, nil)
1027+
1028+
local stats_after = get_stats(g, new_space_name)
1029+
local op_after = stats_after[op]
1030+
t.assert_type(op_after, 'table', "'insert' stats found for new space")
1031+
t.assert_type(op_after.ok, 'table', "success 'insert' stats found for new space")
1032+
t.assert_equals(op_after.ok.count - op_before.ok.count, 1,
1033+
"Success requests count incremented for new space")
1034+
end
1035+
1036+
1037+
pgroup.before_test(
1038+
'test_spaces_dropped_in_runtime_supported_with_stats',
1039+
function(g)
1040+
create_new_space(g)
1041+
1042+
local _, err = g.router:call('crud.insert', { new_space_name, { 1, box.NULL }})
1043+
t.assert_equals(err, nil)
1044+
end)
1045+
1046+
pgroup.test_spaces_dropped_in_runtime_supported_with_stats = function(g)
1047+
local op = 'insert'
1048+
local stats_before = get_stats(g, new_space_name)
1049+
local op_before = get_before_stats(stats_before, op)
1050+
t.assert_type(op_before, 'table', "'insert' stats found for new space")
1051+
1052+
helpers.drop_space_on_cluster(g.cluster, new_space_name)
1053+
1054+
local _, err = g.router:call('crud.insert', { new_space_name, { 2, box.NULL }})
1055+
t.assert_not_equals(err, nil, "Should trigger 'space not found' error")
1056+
1057+
local stats_after = get_stats(g, new_space_name)
1058+
local op_after = stats_after[op]
1059+
t.assert_type(op_after, 'table', "'insert' stats found for dropped new space")
1060+
t.assert_type(op_after.error, 'table', "error 'insert' stats found for dropped new space")
1061+
t.assert_equals(op_after.error.count - op_before.error.count, 1,
1062+
"Error requests count incremented since space was known to registry before drop")
1063+
end

0 commit comments

Comments
 (0)