Skip to content

Commit 5ee659c

Browse files
committed
Refactor parametrizing tests by engine
Implemented ParametrizedGroup class to simplify creating test groups for parametrized tests Added helper functions for space cleanup and stopping cluster
1 parent 970d0df commit 5ee659c

File tree

7 files changed

+226
-237
lines changed

7 files changed

+226
-237
lines changed

test/helper.lua

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ if os.getenv('DEV') == nil then
1313
os.setenv('DEV', 'ON')
1414
end
1515

16+
local helpers = {}
17+
18+
local pgroup = require('test.pgroup')
19+
helpers.pgroup = pgroup
20+
1621
local ok, cartridge_helpers = pcall(require, 'cartridge.test-helpers')
1722
if not ok then
1823
log.error('Please, install cartridge rock to run tests')
1924
os.exit(1)
2025
end
2126

22-
local helpers = table.copy(cartridge_helpers)
27+
for name, value in pairs(cartridge_helpers) do
28+
helpers[name] = value
29+
end
2330

2431
helpers.project_root = fio.dirname(debug.sourcedir())
2532

@@ -105,4 +112,23 @@ function helpers.get_objects_by_idxs(objects, idxs)
105112
return results
106113
end
107114

115+
function helpers.stop_cluster(cluster)
116+
assert(cluster ~= nil)
117+
cluster:stop()
118+
fio.rmtree(cluster.datadir)
119+
end
120+
121+
function helpers.truncate_space_on_cluster(cluster, space_name)
122+
assert(cluster ~= nil)
123+
for _, server in ipairs(cluster.servers) do
124+
server.net_box:eval([[
125+
local space_name = ...
126+
local space = box.space[space_name]
127+
if space ~= nil and not box.cfg.read_only then
128+
space:truncate()
129+
end
130+
]], {space_name})
131+
end
132+
end
133+
108134
return helpers

test/integration/custom_bucket_id_test.lua

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
local fio = require('fio')
22

33
local t = require('luatest')
4-
local g_memtx = t.group('custom_bucket_id_memtx')
5-
local g_vinyl = t.group('custom_bucket_id_vinyl')
6-
74
local crud_utils = require('crud.common.utils')
85

96
local helpers = require('test.helper')
107

11-
local function before_all(g, engine)
8+
local pgroup = helpers.pgroup.new('custom_bucket_id', {
9+
engine = {'memtx', 'vinyl'},
10+
})
11+
12+
pgroup:set_before_all(function(g)
1213
g.cluster = helpers.Cluster:new({
1314
datadir = fio.tempdir(),
1415
server_command = helpers.entrypoint('srv_simple_operations'),
@@ -42,44 +43,20 @@ local function before_all(g, engine)
4243
}
4344
},
4445
env = {
45-
['ENGINE'] = engine,
46+
['ENGINE'] = g.params.engine,
4647
},
4748
})
48-
g.engine = engine
49+
4950
g.cluster:start()
5051

5152
g.space_format = g.cluster.servers[2].net_box.space.customers:format()
52-
end
53-
54-
g_memtx.before_all = function() before_all(g_memtx, 'memtx') end
55-
g_vinyl.before_all = function() before_all(g_vinyl, 'vinyl') end
56-
57-
local function after_all(g)
58-
g.cluster:stop()
59-
fio.rmtree(g.cluster.datadir)
60-
end
61-
62-
g_memtx.after_all = function() after_all(g_memtx) end
63-
g_vinyl.after_all = function() after_all(g_vinyl) end
64-
65-
local function before_each(g)
66-
for _, server in ipairs(g.cluster.servers) do
67-
server.net_box:eval([[
68-
local space = box.space.customers
69-
if space ~= nil and not box.cfg.read_only then
70-
space:truncate()
71-
end
72-
]])
73-
end
74-
end
53+
end)
7554

76-
g_memtx.before_each(function() before_each(g_memtx) end)
77-
g_vinyl.before_each(function() before_each(g_vinyl) end)
55+
pgroup:set_after_all(function(g) helpers.stop_cluster(g.cluster) end)
7856

79-
local function add(name, fn)
80-
g_memtx[name] = fn
81-
g_vinyl[name] = fn
82-
end
57+
pgroup:set_before_each(function(g)
58+
helpers.truncate_space_on_cluster(g.cluster, 'customers')
59+
end)
8360

8461
local function get_other_storage_bucket_id(g, key)
8562
local res_bucket_id, err = g.cluster.main_server.net_box:eval([[
@@ -145,7 +122,7 @@ local function check_get(g, space_name, id, bucket_id, tuple)
145122
t.assert_equals(result.rows, {tuple})
146123
end
147124

148-
add('test_update', function(g)
125+
pgroup:add('test_update', function(g)
149126
local tuple = {2, box.NULL, 'Ivan', 20}
150127
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
151128

@@ -183,7 +160,7 @@ add('test_update', function(g)
183160
t.assert_equals(#result.rows, 1)
184161
end)
185162

186-
add('test_delete', function(g)
163+
pgroup:add('test_delete', function(g)
187164
local tuple = {2, box.NULL, 'Ivan', 20}
188165
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
189166

@@ -235,7 +212,7 @@ add('test_delete', function(g)
235212
t.assert_equals(#result.rows, 0)
236213
end)
237214

238-
add('test_insert_object', function(g)
215+
pgroup:add('test_insert_object', function(g)
239216
local object = {id = 2, name = 'Ivan', age = 46}
240217
local bucket_id = get_other_storage_bucket_id(g, object.id)
241218
object.bucket_id = bucket_id
@@ -254,7 +231,7 @@ add('test_insert_object', function(g)
254231
check_get(g, 'customers', object.id, bucket_id, tuple)
255232
end)
256233

257-
add('test_insert_object_bucket_id_opt', function(g)
234+
pgroup:add('test_insert_object_bucket_id_opt', function(g)
258235
local object = {id = 1, name = 'Fedor', age = 59}
259236
local bucket_id = get_other_storage_bucket_id(g, object.id)
260237

@@ -272,7 +249,7 @@ add('test_insert_object_bucket_id_opt', function(g)
272249
check_get(g, 'customers', object.id, bucket_id, tuple)
273250
end)
274251

275-
add('test_insert_object_bucket_id_specified_twice', function(g)
252+
pgroup:add('test_insert_object_bucket_id_specified_twice', function(g)
276253
local object = {id = 1, name = 'Fedor', age = 59}
277254
local bucket_id = get_other_storage_bucket_id(g, object.id)
278255
object.bucket_id = bucket_id
@@ -299,7 +276,7 @@ add('test_insert_object_bucket_id_specified_twice', function(g)
299276
check_get(g, 'customers', object.id, bucket_id, tuple)
300277
end)
301278

302-
add('test_insert', function(g)
279+
pgroup:add('test_insert', function(g)
303280
local tuple = {2, box.NULL, 'Ivan', 20}
304281
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
305282
tuple[2] = bucket_id
@@ -316,7 +293,7 @@ add('test_insert', function(g)
316293
check_get(g, 'customers', tuple[1], bucket_id, tuple)
317294
end)
318295

319-
add('test_insert_bucket_id_opt', function(g)
296+
pgroup:add('test_insert_bucket_id_opt', function(g)
320297
local tuple = {1, box.NULL, 'Ivan', 20}
321298
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
322299

@@ -335,7 +312,7 @@ add('test_insert_bucket_id_opt', function(g)
335312
check_get(g, 'customers', tuple[1], bucket_id, tuple_with_bucket_id)
336313
end)
337314

338-
add('test_insert_bucket_id_specified_twice', function(g)
315+
pgroup:add('test_insert_bucket_id_specified_twice', function(g)
339316
local tuple = {2, box.NULL, 'Ivan', 20}
340317
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
341318
tuple[2] = bucket_id
@@ -360,7 +337,7 @@ add('test_insert_bucket_id_specified_twice', function(g)
360337
check_get(g, 'customers', tuple[1], bucket_id, tuple)
361338
end)
362339

363-
add('test_replace_object', function(g)
340+
pgroup:add('test_replace_object', function(g)
364341
local object = {id = 2, name = 'Jane', age = 21}
365342
local bucket_id = get_other_storage_bucket_id(g, object.id)
366343
object.bucket_id = bucket_id
@@ -379,7 +356,7 @@ add('test_replace_object', function(g)
379356
check_get(g, 'customers', object.id, bucket_id, tuple)
380357
end)
381358

382-
add('test_replace_object_bucket_id_opt', function(g)
359+
pgroup:add('test_replace_object_bucket_id_opt', function(g)
383360
local object = {id = 1, name = 'John', age = 25}
384361
local bucket_id = get_other_storage_bucket_id(g, object.id)
385362

@@ -397,7 +374,7 @@ add('test_replace_object_bucket_id_opt', function(g)
397374
check_get(g, 'customers', object.id, bucket_id, tuple)
398375
end)
399376

400-
add('test_replace_object_bucket_id_specified_twice', function(g)
377+
pgroup:add('test_replace_object_bucket_id_specified_twice', function(g)
401378
local object = {id = 1, name = 'Fedor', age = 59}
402379
local bucket_id = get_other_storage_bucket_id(g, object.id)
403380
object.bucket_id = bucket_id
@@ -424,7 +401,7 @@ add('test_replace_object_bucket_id_specified_twice', function(g)
424401
check_get(g, 'customers', object.id, bucket_id, tuple)
425402
end)
426403

427-
add('test_replace', function(g)
404+
pgroup:add('test_replace', function(g)
428405
local tuple = {2, box.NULL, 'Jane', 21}
429406
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
430407
tuple[2] = bucket_id
@@ -441,7 +418,7 @@ add('test_replace', function(g)
441418
check_get(g, 'customers', tuple[1], bucket_id, tuple)
442419
end)
443420

444-
add('test_replace_bucket_id_opt', function(g)
421+
pgroup:add('test_replace_bucket_id_opt', function(g)
445422
local tuple = {1, box.NULL, 'John', 25}
446423
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
447424

@@ -460,7 +437,7 @@ add('test_replace_bucket_id_opt', function(g)
460437
check_get(g, 'customers', tuple[1], bucket_id, tuple_with_bucket_id)
461438
end)
462439

463-
add('test_replace_bucket_id_specified_twice', function(g)
440+
pgroup:add('test_replace_bucket_id_specified_twice', function(g)
464441
local tuple = {1, box.NULL, 'John', 25}
465442
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
466443
tuple[2] = bucket_id
@@ -485,7 +462,7 @@ add('test_replace_bucket_id_specified_twice', function(g)
485462
check_get(g, 'customers', tuple[1], bucket_id, tuple)
486463
end)
487464

488-
add('test_upsert_object', function(g)
465+
pgroup:add('test_upsert_object', function(g)
489466
local object = {id = 2, name = 'Jane', age = 21}
490467
local bucket_id = get_other_storage_bucket_id(g, object.id)
491468
object.bucket_id = bucket_id
@@ -504,7 +481,7 @@ add('test_upsert_object', function(g)
504481
check_get(g, 'customers', object.id, bucket_id, tuple)
505482
end)
506483

507-
add('test_upsert_object_bucket_id_opt', function(g)
484+
pgroup:add('test_upsert_object_bucket_id_opt', function(g)
508485
local object = {id = 1, name = 'John', age = 25}
509486
local bucket_id = get_other_storage_bucket_id(g, object.id)
510487

@@ -522,7 +499,7 @@ add('test_upsert_object_bucket_id_opt', function(g)
522499
check_get(g, 'customers', object.id, bucket_id, tuple)
523500
end)
524501

525-
add('test_upsert_object_bucket_id_specified_twice', function(g)
502+
pgroup:add('test_upsert_object_bucket_id_specified_twice', function(g)
526503
local object = {id = 1, name = 'Fedor', age = 59}
527504
local bucket_id = get_other_storage_bucket_id(g, object.id)
528505
object.bucket_id = bucket_id
@@ -549,7 +526,7 @@ add('test_upsert_object_bucket_id_specified_twice', function(g)
549526
check_get(g, 'customers', object.id, bucket_id, tuple)
550527
end)
551528

552-
add('test_upsert', function(g)
529+
pgroup:add('test_upsert', function(g)
553530
local tuple = {1, box.NULL, 'John', 25}
554531
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
555532
tuple[2] = bucket_id
@@ -566,7 +543,7 @@ add('test_upsert', function(g)
566543
check_get(g, 'customers', tuple[1], bucket_id, tuple)
567544
end)
568545

569-
add('test_upsert_bucket_id_opt', function(g)
546+
pgroup:add('test_upsert_bucket_id_opt', function(g)
570547
local tuple = {1, box.NULL, 'John', 25}
571548
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
572549

@@ -585,7 +562,7 @@ add('test_upsert_bucket_id_opt', function(g)
585562
check_get(g, 'customers', tuple[1], bucket_id, tuple_with_bucket_id)
586563
end)
587564

588-
add('test_upsert_bucket_id_specified_twice', function(g)
565+
pgroup:add('test_upsert_bucket_id_specified_twice', function(g)
589566
local tuple = {1, box.NULL, 'John', 25}
590567
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
591568
tuple[2] = bucket_id
@@ -610,7 +587,7 @@ add('test_upsert_bucket_id_specified_twice', function(g)
610587
check_get(g, 'customers', tuple[1], bucket_id, tuple)
611588
end)
612589

613-
add('test_select', function(g)
590+
pgroup:add('test_select', function(g)
614591
local tuple = {2, box.NULL, 'Ivan', 20}
615592
local bucket_id = get_other_storage_bucket_id(g, tuple[1])
616593

0 commit comments

Comments
 (0)