Skip to content

Commit 0f7e4bb

Browse files
Use in-built stats instead on helper in tests
Use in-built `crud.stats()` info instead on `storage_stat` helper in tests to track map reduce calls. Part of #224
1 parent c25e514 commit 0f7e4bb

File tree

5 files changed

+35
-191
lines changed

5 files changed

+35
-191
lines changed

test/helper.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,10 @@ function helpers.update_cache(cluster, space_name)
332332
]], {space_name})
333333
end
334334

335+
function helpers.get_map_reduces_stat(router_net_box)
336+
return router_net_box:eval([[
337+
return require('crud').stats().select.details.map_reduces_planned
338+
]])
339+
end
340+
335341
return helpers

test/helpers/storage_stat.lua

Lines changed: 0 additions & 110 deletions
This file was deleted.

test/integration/ddl_sharding_key_test.lua

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local crud = require('crud')
33
local t = require('luatest')
44

55
local helpers = require('test.helper')
6-
local storage_stat = require('test.helpers.storage_stat')
76

87
local ok = pcall(require, 'ddl')
98
if not ok then
@@ -34,13 +33,6 @@ pgroup.before_all(function(g)
3433
]])
3534
t.assert_equals(type(result), 'table')
3635
t.assert_equals(err, nil)
37-
38-
helpers.call_on_storages(g.cluster, function(server)
39-
server.net_box:eval([[
40-
local storage_stat = require('test.helpers.storage_stat')
41-
storage_stat.init_on_storage()
42-
]])
43-
end)
4436
end)
4537

4638
pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
@@ -349,45 +341,39 @@ for name, case in pairs(cases) do
349341
pgroup[('test_%s_wont_lead_to_map_reduce'):format(name)] = function(g)
350342
case.prepare_data(g, case.space_name)
351343

352-
local stat_a = storage_stat.collect(g.cluster)
344+
local router = g.cluster:server('router').net_box
345+
local map_reduces_before = helpers.get_map_reduces_stat(router)
353346

354-
local result, err = g.cluster.main_server.net_box:call('crud.select', {
347+
local result, err = router:call('crud.select', {
355348
case.space_name, case.conditions
356349
})
357350
t.assert_equals(err, nil)
358351
t.assert_not_equals(result, nil)
359352
t.assert_equals(#result.rows, 1)
360353

361-
local stat_b = storage_stat.collect(g.cluster)
362-
363-
-- Check a number of select() requests made by CRUD on cluster's storages
364-
-- after calling select() on a router. Make sure only a single storage has
365-
-- a single select() request. Otherwise we lead to map-reduce.
366-
local stats = storage_stat.diff(stat_b, stat_a)
367-
t.assert_equals(storage_stat.total(stats), 1, 'Select request was not a map reduce')
354+
local map_reduces_after = helpers.get_map_reduces_stat(router)
355+
local diff = map_reduces_after - map_reduces_before
356+
t.assert_equals(diff, 0, 'Select request was not a map reduce')
368357
end
369358
end
370359

371360
pgroup.test_select_for_part_of_sharding_key_will_lead_to_map_reduce = function(g)
372361
local space_name = 'customers_name_age_key_different_indexes'
373362
prepare_data_name_age_sharding_key(g, space_name)
374363

375-
local stat_a = storage_stat.collect(g.cluster)
364+
local router = g.cluster:server('router').net_box
365+
local map_reduces_before = helpers.get_map_reduces_stat(router)
376366

377-
local result, err = g.cluster.main_server.net_box:call('crud.select', {
367+
local result, err = router:call('crud.select', {
378368
space_name, {{'==', 'age', 58}},
379369
})
380370
t.assert_equals(err, nil)
381371
t.assert_not_equals(result, nil)
382372
t.assert_equals(#result.rows, 1)
383373

384-
local stat_b = storage_stat.collect(g.cluster)
385-
386-
-- Check a number of select() requests made by CRUD on cluster's storages
387-
-- after calling select() on a router. Make sure it was a map-reduce
388-
-- since we do not have sharding key values in conditions.
389-
local stats = storage_stat.diff(stat_b, stat_a)
390-
t.assert_equals(storage_stat.total(stats), 2, 'Select request was a map reduce')
374+
local map_reduces_after = helpers.get_map_reduces_stat(router)
375+
local diff = map_reduces_after - map_reduces_before
376+
t.assert_equals(diff, 1, 'Select request was a map reduce')
391377
end
392378

393379
pgroup.test_select_secondary_idx = function(g)

test/integration/pairs_test.lua

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local t = require('luatest')
55
local crud_utils = require('crud.common.utils')
66

77
local helpers = require('test.helper')
8-
local storage_stat = require('test.helpers.storage_stat')
98

109
local pgroup = t.group('pairs', {
1110
{engine = 'memtx'},
@@ -26,13 +25,6 @@ pgroup.before_all(function(g)
2625
g.cluster:start()
2726

2827
g.space_format = g.cluster.servers[2].net_box.space.customers:format()
29-
30-
helpers.call_on_storages(g.cluster, function(server)
31-
server.net_box:eval([[
32-
local storage_stat = require('test.helpers.storage_stat')
33-
storage_stat.init_on_storage()
34-
]])
35-
end)
3628
end)
3729

3830
pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
@@ -842,10 +834,11 @@ pgroup.test_pairs_no_map_reduce = function(g)
842834

843835
table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)
844836

845-
local stat_a = storage_stat.collect(g.cluster)
837+
local router = g.cluster:server('router').net_box
838+
local map_reduces_before = helpers.get_map_reduces_stat(router)
846839

847840
-- Case: no conditions, just bucket id.
848-
local rows = g.cluster.main_server.net_box:eval([[
841+
local rows = router:eval([[
849842
local crud = require('crud')
850843
851844
return crud.pairs(...):totable()
@@ -858,15 +851,9 @@ pgroup.test_pairs_no_map_reduce = function(g)
858851
{3, 2804, 'David', 'Smith', 33, 'Los Angeles'},
859852
})
860853

861-
local stat_b = storage_stat.collect(g.cluster)
862-
t.assert_equals(storage_stat.diff(stat_b, stat_a), {
863-
['s-1'] = {
864-
select_requests = 1,
865-
},
866-
['s-2'] = {
867-
select_requests = 0,
868-
},
869-
})
854+
local map_reduces_after_1 = helpers.get_map_reduces_stat(router)
855+
local diff_1 = map_reduces_after_1 - map_reduces_before
856+
t.assert_equals(diff_1, 0, 'Select request was not a map reduce')
870857

871858
-- Case: EQ on secondary index, which is not in the sharding
872859
-- index (primary index in the case).
@@ -883,13 +870,7 @@ pgroup.test_pairs_no_map_reduce = function(g)
883870
{4, 1161, 'William', 'White', 81, 'Chicago'},
884871
})
885872

886-
local stat_c = storage_stat.collect(g.cluster)
887-
t.assert_equals(storage_stat.diff(stat_c, stat_b), {
888-
['s-1'] = {
889-
select_requests = 0,
890-
},
891-
['s-2'] = {
892-
select_requests = 1,
893-
},
894-
})
873+
local map_reduces_after_2 = helpers.get_map_reduces_stat(router)
874+
local diff_2 = map_reduces_after_2 - map_reduces_after_1
875+
t.assert_equals(diff_2, 0, 'Select request was not a map reduce')
895876
end

test/integration/select_test.lua

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local crud = require('crud')
66
local crud_utils = require('crud.common.utils')
77

88
local helpers = require('test.helper')
9-
local storage_stat = require('test.helpers.storage_stat')
109

1110
local pgroup = t.group('select', {
1211
{engine = 'memtx'},
@@ -27,13 +26,6 @@ pgroup.before_all(function(g)
2726
g.cluster:start()
2827

2928
g.space_format = g.cluster.servers[2].net_box.space.customers:format()
30-
31-
helpers.call_on_storages(g.cluster, function(server)
32-
server.net_box:eval([[
33-
local storage_stat = require('test.helpers.storage_stat')
34-
storage_stat.init_on_storage()
35-
]])
36-
end)
3729
end)
3830

3931
pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)
@@ -1615,7 +1607,8 @@ pgroup.test_select_no_map_reduce = function(g)
16151607

16161608
table.sort(customers, function(obj1, obj2) return obj1.id < obj2.id end)
16171609

1618-
local stat_a = storage_stat.collect(g.cluster)
1610+
local router = g.cluster:server('router').net_box
1611+
local map_reduces_before = helpers.get_map_reduces_stat(router)
16191612

16201613
-- Case: no conditions, just bucket id.
16211614
local result, err = g.cluster.main_server.net_box:call('crud.select', {
@@ -1628,15 +1621,9 @@ pgroup.test_select_no_map_reduce = function(g)
16281621
{3, 2804, 'David', 'Smith', 33, 'Los Angeles'},
16291622
})
16301623

1631-
local stat_b = storage_stat.collect(g.cluster)
1632-
t.assert_equals(storage_stat.diff(stat_b, stat_a), {
1633-
['s-1'] = {
1634-
select_requests = 1,
1635-
},
1636-
['s-2'] = {
1637-
select_requests = 0,
1638-
},
1639-
})
1624+
local map_reduces_after_1 = helpers.get_map_reduces_stat(router)
1625+
local diff_1 = map_reduces_after_1 - map_reduces_before
1626+
t.assert_equals(diff_1, 0, 'Select request was not a map reduce')
16401627

16411628
-- Case: EQ on secondary index, which is not in the sharding
16421629
-- index (primary index in the case).
@@ -1650,13 +1637,7 @@ pgroup.test_select_no_map_reduce = function(g)
16501637
{4, 1161, 'William', 'White', 81, 'Chicago'},
16511638
})
16521639

1653-
local stat_c = storage_stat.collect(g.cluster)
1654-
t.assert_equals(storage_stat.diff(stat_c, stat_b), {
1655-
['s-1'] = {
1656-
select_requests = 0,
1657-
},
1658-
['s-2'] = {
1659-
select_requests = 1,
1660-
},
1661-
})
1640+
local map_reduces_after_2 = helpers.get_map_reduces_stat(router)
1641+
local diff_2 = map_reduces_after_2 - map_reduces_after_1
1642+
t.assert_equals(diff_2, 0, 'Select request was not a map reduce')
16621643
end

0 commit comments

Comments
 (0)