Skip to content

Commit

Permalink
test: use luatest's parameterization in tests
Browse files Browse the repository at this point in the history
This patch switch regression test suite to use parameterization
in luatest.

Before: Ran 39 tests in 21.062 seconds, 39 successes, 0 failures
After: Ran 105 tests in 37.131 seconds, 105 successes, 0 failures, 67 skipped

Closes #80
  • Loading branch information
ligurio committed Nov 8, 2021
1 parent 35d1f96 commit ead8e1d
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 403 deletions.
9 changes: 1 addition & 8 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ local function create_space(space_name, engine)
end

function helpers.create_space_with_tree_index(engine)
-- Change space name when engine is vinyl to avoid intersection
-- with space "tree" with memtx engine.
-- To be removed in next commit.
local space_name = "tree"
if engine == "vinyl" then
space_name = "vinyl"
end
local space = create_space(space_name, engine)
local space = create_space("tree", engine)

space:create_index("primary", {
type = "TREE",
Expand Down
68 changes: 39 additions & 29 deletions test/unit/atomic_iteration_test.lua
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
local fiber = require("fiber")
local expirationd = require("expirationd")
local t = require("luatest")
local g = t.group("atomic_iteration")

local helpers = require("test.helper")

g.before_each(function()
g.tree = helpers.create_space_with_tree_index("memtx")
g.hash = helpers.create_space_with_hash_index("memtx")
g.bitset = helpers.create_space_with_bitset_index("memtx")
g.vinyl = helpers.create_space_with_tree_index("vinyl")
local g = t.group('atomic_iteration', {
{index_type = 'TREE', engine = 'vinyl'},
{index_type = 'TREE', engine = 'memtx'},
{index_type = 'HASH', engine = 'memtx'},
})

g.before_each({index_type = 'TREE'}, function(cg)
g.space = helpers.create_space_with_tree_index(cg.params.engine)
end)

g.before_each({index_type = 'HASH'}, function(cg)
g.space = helpers.create_space_with_hash_index(cg.params.engine)
end)

g.after_each(function()
g.tree:drop()
g.hash:drop()
g.bitset:drop()
g.vinyl:drop()
g.after_each(function(g)
g.space:drop()
end)

function g.test_passing()
local task = expirationd.start("clean_all", g.tree.id, helpers.is_expired_true)
function g.test_passing(cg)
local task = expirationd.start("clean_all", cg.space.id, helpers.is_expired_true)
t.assert_equals(task.atomic_iteration, false)
task:kill()

task = expirationd.start("clean_all", g.tree.id, helpers.is_expired_true,
task = expirationd.start("clean_all", cg.space.id, helpers.is_expired_true,
{atomic_iteration = true})
t.assert_equals(task.atomic_iteration, true)
task:kill()

-- errors
t.assert_error_msg_content_equals("bad argument options.atomic_iteration to nil (?boolean expected, got number)",
expirationd.start, "clean_all", g.tree.id, helpers.is_expired_true,
expirationd.start, "clean_all", cg.space.id, helpers.is_expired_true,
{atomic_iteration = 1})
end

Expand Down Expand Up @@ -124,34 +127,41 @@ local function test_memtx(space)
box.begin = true_box_begin
end

function g.test_memtx_tree_index()
test_memtx(g.tree)
function g.test_memtx_tree_index(cg)
t.skip_if(cg.params.engine ~= 'memtx', 'Unsupported engine')

test_memtx(cg.space)
end

function g.test_memtx_hash_index()
test_memtx(g.hash)
function g.test_memtx_hash_index(cg)
t.skip_if(cg.params.engine ~= 'memtx', 'Unsupported engine')

test_memtx(cg.space)
end

-- it's not check tarantool or vinyl as engine
-- just check expirationd task continue work after conflicts
function g.test_mvcc_vinyl_tx_conflict()
function g.test_mvcc_vinyl_tx_conflict(cg)
t.skip('Broken on vinyl')
t.skip_if(cg.params.engine ~= 'vinyl', 'Unsupported engine')

for i = 1,10 do
g.vinyl:insert({i, tostring(i), nil, nil, 0})
cg.space:insert({i, tostring(i), nil, nil, 0})
end

local updaters = {}
for i = 1,10 do
local updater = fiber.create(function()
fiber.name(string.format("updater of %d", i), { truncate = true })
while true do
g.vinyl:update({i}, { {"+", 5, 1} })
cg.space:update({i}, { {"+", 5, 1} })
fiber.yield()
end
end)
table.insert(updaters, updater)
end

local task = expirationd.start("clean_all", g.vinyl.id, helpers.is_expired_debug,
local task = expirationd.start("clean_all", cg.space.id, helpers.is_expired_debug,
{atomic_iteration = true})

-- wait for tuples expired
Expand All @@ -162,25 +172,25 @@ function g.test_mvcc_vinyl_tx_conflict()
end

helpers.retrying({}, function()
t.assert_equals(g.vinyl:select(), {})
t.assert_equals(cg.space:select(), {})
end)
t.assert(box.stat.vinyl().tx.conflict > 0)
t.assert_equals(box.stat.vinyl().tx.conflict, box.stat.vinyl().tx.rollback)
t.assert_equals(box.stat.vinyl().tx.transactions, 0)
task:kill()
end

function g.test_kill_task()
function g.test_kill_task(cg)
for i = 1,1024*10 do
g.tree:insert({i, tostring(i)})
cg.space:insert({i, tostring(i)})
end

local task = expirationd.start("clean_all", g.tree.id, helpers.is_expired_debug,
local task = expirationd.start("clean_all", cg.space.id, helpers.is_expired_debug,
{atomic_iteration = true})

task:kill()
t.assert(g.tree:count() > 0)
t.assert(g.tree:count() % 1024 == 0)
t.assert(cg.space:count() > 0)
t.assert(cg.space:count() % 1024 == 0)

-- return to default value
box.cfg{vinyl_memory = 134217728}
Expand Down
Loading

0 comments on commit ead8e1d

Please sign in to comment.