Skip to content

Commit

Permalink
test: testing features from #50
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtDu committed Jun 11, 2021
1 parent d3d2a82 commit ef83248
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 0 deletions.
110 changes: 110 additions & 0 deletions test/unit/atomic_iteration_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
local fio = require('fio')
local expirationd = require('expirationd')
local t = require('luatest')
local g = t.group("transaction")
local xlog = require('xlog').pairs

local helpers = require('luatest.helpers')

local function read_xlog(file)
local val = {}
for k, v in xlog(file) do
table.insert(val, setmetatable(v, { __serialize = "map"}))
end
return val
end

g.before_all(function()
helpers.init_spaces(g)
end)

g.after_each(function()
helpers.truncate_spaces(g)
end)

function g.test_atomic_iteration()
helpers.iteration_result = {}

local transactions = {}
function f(iterator)
local transaction = {}
-- old / new_tuple is not passed for vinyl
for request_number, old_tuple, new_tuple, space_id in iterator() do
require'log'.info(old_tuple:totable())
table.insert(transaction, old_tuple:totable())
end
table.insert(transactions, transaction)
end

local true_box_begin = box.begin

-- mock box.begin
box.begin = function ()
true_box_begin()
box.on_commit(f)
end

for _, space in pairs({g.tree, g.hash}) do
-- tuples expired in one atomic_iteration
space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})


local task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {atomic_iteration = true})
-- wait for tuples expired
helpers.retrying({}, function()
if space.index[0].type == "HASH" then
t.assert_equals(helpers.iteration_result, {{3, '1'}, {2, '2'}, {1, '3'}})
else
t.assert_equals(helpers.iteration_result, {{1, '3'}, {2, '2'}, {3, '1'}})
end
end)
task:kill()
helpers.iteration_result = {}

-- check out three row transaction
if space.index[0].type == "HASH" then
t.assert_equals(transactions, {
{ {3, '1'}, {2, '2'}, {1, '3'} }
})
else
t.assert_equals(transactions, {
{ {1, '3'}, {2, '2'}, {3, '1'} }
})
end
transactions = {}

-- tuples expired in two atomic_iteration
space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})

task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {atomic_iteration = true, tuples_per_iteration = 2})
-- wait for tuples expired
-- 2 seconds because suspend will be yield in task
helpers.retrying({}, function()
if space.index[0].type == "HASH" then
t.assert_equals(helpers.iteration_result, {{3, '1'}, {2, '2'}, {1, '3'}})
else
t.assert_equals(helpers.iteration_result, {{1, '3'}, {2, '2'}, {3, '1'}})
end
end)
task:kill()
helpers.iteration_result = {}

if space.index[0].type == "HASH" then
t.assert_equals(transactions, {
{ {3, '1'}, {2, '2'} }, -- check two row transaction
{ {1, '3'} } -- check single row transactions
})
else
t.assert_equals(transactions, {
{ {1, '3'}, {2, '2'} }, -- check two row transaction
{ {3, '1'} } -- check single row transactions
})
end

transactions = {}
end
end
81 changes: 81 additions & 0 deletions test/unit/iterating_by_custom_index_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
local expirationd = require('expirationd')
local t = require('luatest')
local g = t.group("iterating_by_custom_index")

local helpers = require('luatest.helpers')

g.before_all(function()
helpers.init_spaces(g)
end)

g.after_each(function()
helpers.truncate_spaces(g)
end)

function g.test_tree_index()
for _, space in pairs({g.tree, g.vinyl}) do
helpers.iteration_result = {}

space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})

local task = expirationd.start("clean_all", space.id, helpers.is_expired_debug)
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{1, '3'}, {2, '2'}, {3, '1'}})
end)
task:kill()
helpers.iteration_result = {}

space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})

task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {index = 'index_for_first_name'})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{3, '1'}, {2, '2'}, {1, '3'}})
end)
task:kill()
helpers.iteration_result = {}

space:insert({1, "1", 2, 1})
space:insert({2, "2", 2, 2})
space:insert({3, "3", 1, 3})

task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {index = 'multipart_index'})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{3, '3', 1, 3}, {1, '1', 2, 1}, {2, '2', 2, 2}})
end)
task:kill()
end
end

function g.test_hash_index()
helpers.iteration_result = {}
g.hash:insert({1, "a"})
g.hash:insert({2, "b"})
g.hash:insert({3, "c"})

local task = expirationd.start("clean_all", g.hash.id, helpers.is_expired_debug)
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{3, 'c'}, {2, 'b'}, {1, 'a'}})
end)
task:kill()

helpers.iteration_result = {}
g.hash:insert({1, "a"})
g.hash:insert({2, "b"})
g.hash:insert({3, "c"})

task = expirationd.start("clean_all", g.hash.id, helpers.is_expired_debug, {index = 'index_for_first_name'})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{1, 'a'}, {3, 'c'}, {2, 'b'}})
end)
helpers.iteration_result = {}
task:kill()
end
29 changes: 29 additions & 0 deletions test/unit/iterator_type_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local expirationd = require('expirationd')
local t = require('luatest')
local g = t.group("iterator_type")

local helpers = require('luatest.helpers')

g.before_all(function()
helpers.init_spaces(g)
end)

g.after_each(function()
helpers.truncate_spaces(g)
end)

function g.test_tree_index()
for _, space in pairs({g.tree, g.vinyl}) do
helpers.iteration_result = {}
space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})

local task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {iterator_type = "LE"})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{3, '1'}, {2, '2'}, {1, '3'}})
end)
task:kill()
end
end
47 changes: 47 additions & 0 deletions test/unit/process_while_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
local expirationd = require('expirationd')
local t = require('luatest')
local g = t.group("process_while")

local helpers = require('luatest.helpers')

g.before_all(function()
helpers.init_spaces(g)
end)

g.after_each(function()
helpers.truncate_spaces(g)
end)

function g.test_stopper()
helpers.iteration_result = {}
local function process_while(task)
if task.checked_tuples_count >= 1 then return false end
return true
end

-- for tree index spaces
for _, space in pairs({g.tree, g.vinyl}) do
space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})
local task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {process_while = process_while})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{1, "3"}})
end)
task:kill()
helpers.iteration_result = {}
end

-- for hash index space
g.hash:insert({1, "3"})
g.hash:insert({2, "2"})
g.hash:insert({3, "1"})

local task = expirationd.start("clean_all", g.hash.id, helpers.is_expired_debug, {process_while = process_while})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{3, "1"}})
end)
task:kill()
end
29 changes: 29 additions & 0 deletions test/unit/start_key_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local expirationd = require('expirationd')
local t = require('luatest')
local g = t.group("start_key")

local helpers = require('luatest.helpers')

g.before_all(function()
helpers.init_spaces(g)
end)

g.after_each(function()
helpers.truncate_spaces(g)
end)

function g.test_tree_index()
for _, space in pairs({g.tree, g.vinyl}) do
helpers.iteration_result = {}
space:insert({1, "3"})
space:insert({2, "2"})
space:insert({3, "1"})

local task = expirationd.start("clean_all", space.id, helpers.is_expired_debug, {start_key = 2})
-- wait for tuples expired
helpers.retrying({}, function()
t.assert_equals(helpers.iteration_result, {{2, '2'}, {3, '1'} })
end)
task:kill()
end
end

0 comments on commit ef83248

Please sign in to comment.