Skip to content

Commit

Permalink
xxx
Browse files Browse the repository at this point in the history
Fixes #
Closes #
Needed for #
See also #

NO_CHANGELOG=internal
NO_DOC=internal
NO_TEST=internal
  • Loading branch information
ligurio committed Jul 3, 2023
1 parent a5614c4 commit 631258e
Showing 1 changed file with 46 additions and 42 deletions.
88 changes: 46 additions & 42 deletions test/app-luatest/gh_6128_background_mode_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ end
-- and reads the whole log file every time, but this log file has a small
-- size so it is ok.
-- https://github.com/tarantool/luatest/blob/89da427f8bb3bb66e01d2a7b5a9370d0428d8c52/luatest/server.lua#L660-L727
local function check_err_msg(file, msg)
local f = fio.open(file, {'O_RDONLY', 'O_NONBLOCK'})
t.assert_not_equals(f, nil)
local content = f:read(2048)
print(content)
f:close()
return (string.match(content, msg) and true) or false
end
-- local function check_err_msg(file, msg)
-- local f = fio.open(file, {'O_RDONLY', 'O_NONBLOCK'})
-- t.assert_not_equals(f, nil)
-- local content = f:read(2048)
-- 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")
g.before_test("test_background_mode_box_cfg", function(cg)
cg.work_dir = fio.tempdir()
cg.log_path = fio.pathjoin(cg.work_dir, "tarantool.log")
cg.pid_path = fio.pathjoin(cg.work_dir, "tarantool.pid")

t.assert_equals(fio.path.exists(g.log_path), false)
t.assert_equals(fio.path.exists(g.pid_path), false)
t.assert_equals(fio.path.exists(cg.log_path), false)
t.assert_equals(fio.path.exists(cg.pid_path), false)

local box_cfg = string.format([[-e box.cfg{
pid_file='%s', background=true, work_dir='%s', log='%s',
}]], g.pid_path, g.work_dir, g.log_path)
}]], cg.pid_path, cg.work_dir, cg.log_path)
local cmd = {
TARANTOOL_PATH, box_cfg,
}
Expand All @@ -50,15 +49,15 @@ pid_file='%s', background=true, work_dir='%s', log='%s',
})

-- Start Tarantool and check that at least a log file has been created.
t.assert_is_not(g.ph, nil)
t.assert_is_not(cg.ph, nil)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
assert(fio.path.exists(path) == true)
end, g.log_path)
end, cg.log_path)
end)

g.after_test("test_background_mode_box_cfg", function(cg)
cg.ph:terminate()
cg.ph:wait()
-- require('log').info(cg.ph:info())
cg.ph:kill()
cg.ph:close()
fio.unlink(cg.pid_path)
fio.unlink(cg.log_path)
Expand All @@ -67,40 +66,43 @@ g.after_test("test_background_mode_box_cfg", function(cg)
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)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
-- assert(check_err_msg(cg.log_path, msg_opt_processing) == true)
local server = t.Server:new({})
assert(server:grep_log(msg_opt_processing, 1024, {filename = path}) ~= nil)
end, cg.log_path)
end

g.before_test("test_background_mode_env_vars", function()
g.before_test("test_background_mode_env_vars", function(cg)
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)
cg.work_dir = fio.tempdir()
cg.log_path = fio.pathjoin(cg.work_dir, "tarantool.log")
cg.pid_path = fio.pathjoin(cg.work_dir, "tarantool.pid")
t.assert_equals(fio.path.exists(cg.log_path), false)
t.assert_equals(fio.path.exists(cg.pid_path), false)

local env = {}
env["TT_PID_FILE"] = g.pid_path
env["TT_LOG"] = g.log_path
env["TT_PID_FILE"] = cg.pid_path
env["TT_LOG"] = cg.log_path
env["TT_BACKGROUND"] = "true"
env["TT_WORK_DIR"] = g.work_dir
g.ph = popen.new(cmd, {
env["TT_WORK_DIR"] = cg.work_dir
cg.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)
print("XXXXXXXXXXXXXXXXXXXX", g.log_path)
t.assert_is_not(cg.ph, nil)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
assert(fio.path.exists(path) == true)
end, g.log_path)
-- assert(fio.path.exists(path) == true)
local server = t.Server:new({})
assert(server:grep_log(msg_opt_processing, 1024, {filename = path}) ~= nil)
end, cg.log_path)
end)

g.after_test("test_background_mode_env_vars", function(cg)
cg.ph:terminate()
cg.ph:wait()
-- require('log').info(g.ph:info())
cg.ph:kill()
cg.ph:close()
fio.unlink(cg.pid_path)
fio.unlink(cg.log_path)
Expand All @@ -109,8 +111,10 @@ g.after_test("test_background_mode_env_vars", function(cg)
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)
t.helpers.retrying({timeout = 2, delay = 0.01}, function(path)
-- assert(check_err_msg(cg.log_path, msg_opt_processing) == true)
local server = t.Server:new({})
assert(server:grep_log(msg_opt_processing, 1024, {filename = path}) ~= nil)
end, cg.log_path)
-- check_err_msg(cg.log_path, msg_opt_processing)
end

0 comments on commit 631258e

Please sign in to comment.