Skip to content
Snippets Groups Projects
Commit 62df7880 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Feodor Alexandrov
Browse files

test: testing tarantool in background mode

Before a commit ec1af129 ("box: do not close xlog file descriptors in
the atfork handler") there was a bug when Tarantool with enabled
background mode via environment variable could lead a crash:

NO_WRAP
```
$ TT_PID_FILE=tarantool.pid TT_LOG=tarantool.log TT_BACKGROUND=true TT_LISTEN=3301 tarantool -e 'box.cfg{}'
$ tail -3 tarantool.log
2021-11-02 16:05:43.672 [2341202] main init.c:696 E> LuajitError: cannot read stdin: Resource temporarily unavailable
2021-11-02 16:05:43.672 [2341202] main F> fatal error, exiting the event loop
2021-11-02 16:05:43.672 [2341202] main F> fatal error, exiting the event loop
```
NO_WRAP

With commit ec1af129 ("box: do not close xlog file descriptors in
the atfork handler") described bug could not be reproduced.

Proposed patch adds a test that starts Tarantool in background mode
enabled via box.cfg option and via environment variable TT_BACKGROUND to
make sure this behaviour will not be broken in a future.

Closes #6128

NO_DOC=test

(cherry picked from commit f676fb7c)
parent 4b0d4d98
No related branches found
No related tags found
No related merge requests found
## bugfix/core
* Fixed a crash that could happen when Tarantool is started in the
[background mode](https://www.tarantool.io/en/doc/latest/reference/configuration/#confval-background)
(gh-6128).
local t = require("luatest")
local popen = require("popen")
local fio = require("fio")
local g = t.group()
local msg_opt_processing = "entering the event loop"
local function tarantool_path(arg)
local index = -2
-- arg[-1] is guaranteed to be non-null
while arg[index] do index = index - 1 end
return arg[index + 1]
end
local function check_err_msg(file, msg)
local f = io.open(file, "rb")
t.assert_not_equals(f, nil)
local content = f:read("*all")
f:close()
return (string.match(content, msg) and true) or false
end
local TARANTOOL_PATH = tarantool_path(arg)
g.before_test("test_background_mode_box_cfg", function()
g.work_dir = fio.tempdir()
g.log_path = fio.pathjoin(g.work_dir, "tarantool.log")
g.pid_path = fio.pathjoin(g.work_dir, "tarantool.pid")
t.assert_equals(fio.path.exists(g.log_path), false)
t.assert_equals(fio.path.exists(g.pid_path), false)
local box_cfg = string.format([[-e box.cfg{
pid_file='%s', background=true, work_dir='%s', log='%s', log_level=7,
}]], g.pid_path, g.work_dir, g.log_path)
local cmd = {
TARANTOOL_PATH, box_cfg,
}
g.ph = popen.new(cmd, {
stderr = popen.opts.PIPE,
stdin = popen.opts.PIPE,
stdout = popen.opts.PIPE,
})
-- Start Tarantool and check that at least a log file has been created.
t.assert_is_not(g.ph, nil)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
assert(fio.path.exists(path) == true)
end, g.log_path)
end)
g.after_test("test_background_mode_box_cfg", function(cg)
cg.ph:terminate()
cg.ph:wait()
cg.ph:close()
fio.unlink(cg.pid_path)
fio.unlink(cg.log_path)
os.remove("*.xlog")
os.remove("*.snap")
end)
g.test_background_mode_box_cfg = function(cg)
t.helpers.retrying({timeout = 2, delay = 0.01}, function()
assert(check_err_msg(cg.log_path, msg_opt_processing) == true)
end, cg.log_path, cg.ph)
end
g.before_test("test_background_mode_env_vars", function()
local cmd = { TARANTOOL_PATH, "-e", "box.cfg{}" }
g.work_dir = fio.tempdir()
g.log_path = fio.pathjoin(g.work_dir, "tarantool.log")
g.pid_path = fio.pathjoin(g.work_dir, "tarantool.pid")
t.assert_equals(fio.path.exists(g.log_path), false)
t.assert_equals(fio.path.exists(g.pid_path), false)
local env = {}
env["TT_PID_FILE"] = g.pid_path
env["TT_LOG"] = g.log_path
env["TT_BACKGROUND"] = "true"
env["TT_WORK_DIR"] = g.work_dir
g.ph = popen.new(cmd, {
stderr = popen.opts.PIPE,
stdin = popen.opts.PIPE,
stdout = popen.opts.PIPE,
env = env,
})
t.assert_is_not(g.ph, nil)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
assert(fio.path.exists(path) == true)
end, g.log_path)
end)
g.after_test("test_background_mode_env_vars", function(cg)
cg.ph:terminate()
cg.ph:wait()
cg.ph:close()
fio.unlink(cg.pid_path)
fio.unlink(cg.log_path)
os.remove("*.xlog")
os.remove("*.snap")
end)
g.test_background_mode_env_vars = function(cg)
t.helpers.retrying({timeout = 2, delay = 0.01}, function()
assert(check_err_msg(cg.log_path, msg_opt_processing) == true)
end, cg.log_path, cg.ph)
check_err_msg(cg.log_path, msg_opt_processing)
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