1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!/usr/bin/env tarantool
--
-- Testing init script
--
box.cfg{
listen = os.getenv("LISTEN"),
pid_file = "box.pid",
memtx_memory=107374182,
log="tarantool.log"
}
yaml = require('yaml')
fiber = require('fiber')
if box.space.tweedledum ~= nil then
box.space.space1:drop()
end
space = box.schema.space.create('tweedledum')
space:create_index('primary', { type = 'hash' })
print[[
--
-- Access to box.cfg from init script
--
]]
t = {}
for k,v in pairs(box.cfg) do
if k == 'listen' then
v = 'port'
end
if type(v) ~= 'table' and type(v) ~= 'function' then
table.insert(t,k..':'..tostring(v))
end
end
table.sort(t)
print('box.cfg')
for k,v in pairs(t) do print(v) end
--
-- Insert tests
--
local function do_insert()
space:insert{1, 2, 4, 8}
end
fiber1 = fiber.create(do_insert)
print[[
--
-- Test insert from detached fiber
--
]]
print(yaml.encode(space:select()))
print[[
--
-- Test insert from init script
--
]]
space:insert{2, 4, 8, 16}
print(space:get(1))
print(space:get(2))
--
-- Run a dummy insert to avoid race conditions under valgrind
--
space:insert{4, 8, 16}
print(space:get(4))
print[[
--
-- Check that require function(math.floor) reachable in the init script
--
]]
floor = require("math").floor
print(floor(0.5))
print(floor(0.9))
print(floor(1.1))
mod = require('require_mod')
print(mod.test(10, 15))
--
-- A test case for https://github.com/tarantool/tarantool/issues/53
--
assert (require ~= nil)
fiber.sleep(0.0)
assert (require ~= nil)
space:drop()
os.exit()
|