effil/tests/lua/gc-stress.lua
mihacooper 641d111c23 Fix strong reference race in GC (#65)
* Fix strong reference race in GC
* Add regress test
* Fix type stored in StoredObject
* Fix thread input arguments lifetime
2017-09-11 15:39:47 +03:00

41 lines
1.0 KiB
Lua

require "bootstrap-tests"
test.gc_stress.tear_down = default_tear_down
-- Regress test for simultaneous object creation and removing
-- may cause SIGFAULT, so it's marked as "stress"
test.gc_stress.create_and_collect_in_parallel = function ()
function worker()
effil = require "effil"
local nested_table = {
{}, --[[1 level]]
{{}}, --[[2 levels]]
{{{}}}, --[[3 levels]]
{{{{}}}} --[[4 levels]]
}
for i = 1, 100 do
for t = 1, 10 do
local tbl = effil.table(nested_table)
for l = 1, 10 do
tbl[l] = nested_table
end
end
collectgarbage()
effil.gc.collect()
end
end
local thread_num = 10
local threads = {}
for i = 1, thread_num do
threads[i] = effil.thread(worker)(i)
end
for i = 1, thread_num do
test.equal(threads[i]:wait(), "completed")
end
test.equal(effil.gc.count(), 1)
end