Skip to content
Snippets Groups Projects
Commit 99568619 authored by Alexander Turenko's avatar Alexander Turenko Committed by Alexander Turenko
Browse files

test: fix flaky box.cfg() env vars test

The test starts a child tarantool instance in the current working
directory and run box.cfg(). The current working directory is a source
directory. test-run.py runs many tests from it in parallel and in some
circumstances it appears that the directory is locked by some other
box.cfg() call from some other tarantool instance (maybe another test is
doing the same).

The test is rewritten to use a temporary directory for such runs.

The test.interactive_tarantool helper is used for convenience instead of
a popen wrapper that is written specifically for the test.

NO_DOC=It is a fix of a test.
NO_CHANGELOG=see NO_DOC

(cherry picked from commit dfa67ae6)
parent 40aa4df6
No related branches found
No related tags found
No related merge requests found
local fun = require('fun')
local server = require('luatest.server')
local popen = require('popen')
local clock = require('clock')
local treegen = require('test.treegen')
local it = require('test.interactive_tarantool')
local t = require('luatest')
local g = t.group()
g.after_each = function()
g.before_all(function(g)
treegen.init(g)
end)
g.before_each(function(g)
g.dir = treegen.prepare_directory(g, {}, {})
end)
g.after_each(function(g)
if g.child ~= nil then
g.child:close()
end
if g.server ~= nil then
g.server:stop()
end
end
end)
local TARANTOOL_PATH = arg[-1]
local function popen_run(command)
local cmd = TARANTOOL_PATH .. ' -i 2>&1'
local ph = popen.new({cmd}, {
shell = true,
setsid = true,
group_signal = true,
stdout = popen.opts.PIPE,
stderr = popen.opts.DEVNULL,
stdin = popen.opts.PIPE,
})
t.assert(ph, 'process is not up')
ph:write(command)
local output = ''
local time_quota = 10.0
local start_time = clock.monotonic()
while clock.monotonic() - start_time < time_quota do
local chunk = ph:read({timeout = 1.0})
if chunk == '' or chunk == nil then
-- EOF or error
break
end
output = output .. chunk
end
g.after_all(function(g)
treegen.clean(g)
end)
ph:close()
return output
end
-- Disable hide/show prompt functionality, because it breaks a
-- command echo check. The reason is that the 'scheduled next
-- checkpoint' log message is issued from a background fiber.
local env_default = {
TT_CONSOLE_HIDE_SHOW_PROMPT = 'false',
}
g.test_json_table_curly_bracket = function()
local env = {["TT_METRICS"] = '{"labels":{"alias":"gh_8051"},' ..
......@@ -53,17 +45,20 @@ g.test_json_table_curly_bracket = function()
t.assert_equals(g.server:get_box_cfg().metrics.labels.alias, 'gh_8051')
end
g.test_json_table_square_bracket = function()
local res = popen_run([=[
os.setenv('TT_LISTEN', '["localhost:0"]')
box.cfg{}
box.cfg.listen
]=])
g.test_json_table_square_bracket = function(g)
g.child = it.new({
env = fun.chain(env_default, {
TT_LISTEN = '["localhost:0"]',
}):tomap(),
})
local command = ('box.cfg({work_dir = %q})'):format(g.dir)
g.child:roundtrip(command)
t.assert_str_contains(res, "- ['localhost:0']")
g.child:roundtrip('box.cfg.listen', {'localhost:0'})
end
g.test_plain_table = function()
g.test_plain_table = function(g)
local env = {["TT_LOG_MODULES"] = 'aaa=info,bbb=error'}
g.server = server:new{alias='plain_table', env=env}
......@@ -73,20 +68,26 @@ g.test_plain_table = function()
{['aaa'] = 'info', ['bbb'] = 'error'})
end
g.test_format_error = function()
local res = popen_run([[
os.setenv('TT_LOG_MODULES', 'aaa=info,bbb')
box.cfg{}
]])
g.test_format_error = function(g)
g.child = it.new({
env = fun.chain(env_default, {
TT_LOG_MODULES = 'aaa=info,bbb',
}):tomap(),
})
t.assert_str_contains(res, "in `key=value` or `value` format'")
local command = ('box.cfg({work_dir = %q})'):format(g.dir)
local exp_err = 'in `key=value` or `value` format'
t.assert_error_msg_contains(exp_err, g.child.roundtrip, g.child, command)
end
g.test_format_error_empty_key = function()
local res = popen_run([[
os.setenv('TT_LOG_MODULES', 'aaa=info,=error')
box.cfg{}
]])
g.child = it.new({
env = fun.chain(env_default, {
TT_LOG_MODULES = 'aaa=info,=error',
}):tomap(),
})
t.assert_str_contains(res, "`key` must not be empty'")
local command = ('box.cfg({work_dir = %q})'):format(g.dir)
local exp_err = '`key` must not be empty'
t.assert_error_msg_contains(exp_err, g.child.roundtrip, g.child, command)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment