diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 346ba61bc61d1e54aca3f1ba7d71503334780cc4..1e9c890abe81db09b3c702a4af8a293d91222ab4 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -266,26 +266,26 @@ local function load_default_file(default_file) local user_data = ffi.C.getpwnam(ffi.cast('const char*', d.username)) if user_data == nil then log.error('Unknown user: %s', d.username) - os.exit(-1) + os.exit(1) end -- get group data local group = ffi.C.getgrgid(user_data.pw_gid) if group == nil then log.error('Group lookup by gid failed: %d', user_data.pw_gid) - os.exit(-1) + os.exit(1) end group_name = ffi.string(group.gr_name) end if instance_dir == nil then log.error('Instance directory (instance_dir) is not set in %s', default_file) - os.exit(-1) + os.exit(1) end if not fio.stat(instance_dir) then log.error('Instance directory %s does not exist', instance_dir) - os.exit(-1) + os.exit(1) end end @@ -312,7 +312,7 @@ local function mkdir(dirname) log.info("mkdir %s", dirname) if not fio.mkdir(dirname, tonumber('0750', 8)) then log.error("Can't mkdir %s: %s", dirname, errno.strerror()) - os.exit(-1) + os.exit(1) end if not usermode and @@ -568,12 +568,12 @@ local function start() local stat = check_file(instance_path) if stat ~= nil then log.error("Error, while checking syntax: halting") - return 1 + os.exit(1) end local pid = start_check() if pid then log.error("The daemon is already running: PID %s", pid) - return 1 + os.exit(1) end box.cfg = wrapper_cfg require('title').update{ @@ -609,7 +609,7 @@ local function stop() local f = fio.open(pid_file, 'O_RDONLY') if f == nil then log.error("Can't read pid file %s: %s", pid_file, errno.strerror()) - return -1 + return 1 end local pid = tonumber(f:read(64)) @@ -617,13 +617,14 @@ local function stop() if pid == nil or pid <= 0 then log.error("Broken pid file %s", pid_file) - return -1 + return 1 end if ffi.C.kill(pid, 15) < 0 then log.error("Can't kill process %d: %s", pid, errno.strerror()) - return -1 + return 1 end + return 0 end @@ -690,7 +691,7 @@ local function enter() log.error("Please add $USER to group '%s': usermod -a -G %s $USER", group_name, group_name) end - return -1 + return 1 end local cmd = string.format("require('console').connect('%s')", console_sock) @@ -922,7 +923,7 @@ local function process_local(cmd_function) if not fio.stat(instance_path) then log.error('Instance %s is not found in %s', instance_name, instance_dir) - os.exit(-1) + os.exit(1) end -- create a path to the control socket (admin console) diff --git a/test/app-tap/suite.ini b/test/app-tap/suite.ini index 0795f278f139ff9db4b18950254193bfd2283a8c..f44df4a93bfa447d1d53a057faca7335f31a5166 100644 --- a/test/app-tap/suite.ini +++ b/test/app-tap/suite.ini @@ -2,4 +2,3 @@ core = app description = application server tests (TAP) lua_libs = lua/require_mod.lua lua/serializer_test.lua -disabled = tarantoolctl.test.lua diff --git a/test/app-tap/tarantoolctl.result b/test/app-tap/tarantoolctl.result index a758269fdf954977921b09121b567c09b01d31a7..24366da8819d8a6ee71794d0bbc9166836dba1fe 100644 --- a/test/app-tap/tarantoolctl.result +++ b/test/app-tap/tarantoolctl.result @@ -2,44 +2,44 @@ TAP version 13 1..6 # basic test 1..16 - ok - check 'start' command status - ok - check 'start' stderr - ok - check 'status' command status - ok - check 'status' stderr - ok - check 'start' command status - ok - check 'start' stderr - ok - check 'status' command status - ok - check 'status' stderr - ok - check 'stop' command status - ok - check 'stop' stderr - ok - check 'status' command status - ok - check 'status' stderr - ok - check 'stop' command status - ok - check 'stop' stderr - ok - check 'status' command status - ok - check 'status' stderr + ok - check 'start' command status for 'script' + ok - check 'start' stderr for 'script' + ok - check 'status' command status for 'script' + ok - check 'status' stderr for 'script' + ok - check 'start' command status for 'script' + ok - check 'start' stderr for 'script' + ok - check 'status' command status for 'script' + ok - check 'status' stderr for 'script' + ok - check 'stop' command status for 'script' + ok - check 'stop' stderr for 'script' + ok - check 'status' command status for 'script' + ok - check 'status' stderr for 'script' + ok - check 'stop' command status for 'script' + ok - check 'stop' stderr for 'script' + ok - check 'status' command status for 'script' + ok - check 'status' stderr for 'script' # basic test: end ok - basic test # basic test for bad script 1..8 - ok - check 'start' command status - ok - check 'start' stderr - ok - check 'start' command status - ok - check 'start' stderr - ok - check 'start' command status - ok - check 'eval' command status - ok - check 'eval' stderr - ok - check 'stop' command status + ok - check 'start' command status for 'script' + ok - check 'start' stderr for 'script' + ok - check 'start' command status for 'bad_script' + ok - check 'start' stderr for 'bad_script' + ok - check 'start' command status for 'good_script' + ok - check 'eval' command status for 'good_script bad_script.lua' + ok - check 'eval' stderr for 'good_script bad_script.lua' + ok - check 'stop' command status for 'good_script' # basic test for bad script: end ok - basic test for bad script # check answers in case of call 1..6 - ok - check 'start' command status - ok - check 'eval' command status - ok - check 'eval' stderr - ok - check 'eval' command status - ok - check 'eval' stdout - ok - check 'stop' command status + ok - check 'start' command status for 'good_script' + ok - check 'eval' command status for 'good_script bad_script.lua' + ok - check 'eval' stderr for 'good_script bad_script.lua' + ok - check 'eval' command status for 'good_script ok_script.lua' + ok - check 'eval' stdout for 'good_script ok_script.lua' + ok - check 'stop' command status for 'good_script' # check answers in case of call: end ok - check answers in case of call # check basic help @@ -52,7 +52,7 @@ ok - check answers in case of call ok - check basic help # fill and test cat output 1..15 - ok - check 'start' command status + ok - check 'start' command status for 'filler' ok - cat result ok - cat line count ok - cat + --show-system result @@ -69,13 +69,13 @@ ok - check basic help ok - cat + --from=6 --to=3 --format=json --show-system line count # fill and test cat output: end ok - fill and test cat output - # fill and test cat output + # fill and test play output 1..6 - ok - check 'start' command status + ok - check 'start' command status for 'filler' ok - check lsn before ok - execution result ok - check lsn after ok - execution result ok - check lsn after - # fill and test cat output: end -ok - fill and test cat output + # fill and test play output: end +ok - fill and test play output diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index a10cd0c148c4fe4e808764062fe9ecc8ea2a8cf7..0e96915f5dc7e73a1c838cf6ac096a8948afb848 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -5,9 +5,35 @@ local fio = require('fio') local tap = require('tap') local uuid = require('uuid') local yaml = require('yaml') +local errno = require('errno') local fiber = require('fiber') local test_run = require('test_run').new() +local function recursive_rmdir(path) + path = fio.abspath(path) + local path_content = fio.glob(fio.pathjoin(path, '*')) + for _, val in ipairs(fio.glob(fio.pathjoin(path, '.*'))) do + if fio.basename(val) ~= '.' and fio.basename(val) ~= '..' then + table.insert(path_content, val) + end + end + for _, file in ipairs(path_content) do + local stat = fio.stat(file) + if stat:is_dir() then + recursive_rmdir(file) + else + if fio.unlink(file) == false then + print(string.format('!!! failed to unlink file "%s"', file)) + print(string.format('!!! [errno %s]: %s', errno(), errno.strerror())) + end + end + end + if fio.rmdir(path) == false then + print(string.format('!!! failed to rmdir path "%s"', file)) + print(string.format('!!! [errno %s]: %s', errno(), errno.strerror())) + end +end + ffi.cdef[[ typedef int32_t pid_t; int kill(pid_t pid, int sig); @@ -55,9 +81,10 @@ local function run_command(dir, command) local line = [[/bin/sh -c 'cd "%s" && %s >"%s" 2>"%s"']] line = line:format(dir, command, fstdout, fstderr) local res = os.execute(line) + fiber.sleep(0.1) local fstdout_e, fstderr_e = io.open(fstdout):read('*a'), io.open(fstderr):read('*a') fio.unlink(fstdout); fio.unlink(fstderr); - return res, fstdout_e, fstderr_e + return res/256, fstdout_e, fstderr_e end local function tctl_command(dir, cmd, args) @@ -72,19 +99,28 @@ end local function check_ok(test, dir, cmd, args, e_res, e_stdout, e_stderr) local res, stdout, stderr = tctl_command(dir, cmd, args) stdout, stderr = stdout or '', stderr or '' + local ares = true if (e_res ~= nil) then - test:is(res, e_res, ("check '%s' command status"):format(cmd)) + local val = test:is(res, e_res, ("check '%s' command status for '%s'"):format(cmd,args)) + ares = ares and val end if e_stdout ~= nil then - if not test:ok(stdout:find(e_stdout), ("check '%s' stdout"):format(cmd)) then + local val = test:is(res, e_res, ("check '%s' stdout for '%s'"):format(cmd,args)) + ares = ares and val + if not val then print(("Expected to find '%s' in '%s'"):format(e_stdout, stdout)) end end if e_stderr ~= nil then - if not test:ok(stderr:find(e_stderr), ("check '%s' stderr"):format(cmd)) then + local val = test:ok(stderr:find(e_stderr), ("check '%s' stderr for '%s'"):format(cmd,args)) + ares = ares and val + if not val then print(("Expected to find '%s' in '%s'"):format(e_stderr, stderr)) end end + if not ares then + print(res, stdout, stderr) + end end local test = tap.test('tarantoolctl') @@ -100,19 +136,19 @@ do local status, err = pcall(function() test:test("basic test", function(test_i) test_i:plan(16) - check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") - check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") - check_ok(test_i, dir, 'start', 'script', 256, nil, "is already running") - check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") - check_ok(test_i, dir, 'stop', 'script', 0, nil, "Stopping") - check_ok(test_i, dir, 'status', 'script', 256, nil, "is stopped") - check_ok(test_i, dir, 'stop', 'script', 0, nil, "is not running") - check_ok(test_i, dir, 'status', 'script', 256, nil, "is stopped" ) + check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") + check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") + check_ok(test_i, dir, 'start', 'script', 1, nil, "is already running") + check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") + check_ok(test_i, dir, 'stop', 'script', 0, nil, "Stopping") + check_ok(test_i, dir, 'status', 'script', 1, nil, "is stopped") + check_ok(test_i, dir, 'stop', 'script', 0, nil, "is not running") + check_ok(test_i, dir, 'status', 'script', 1, nil, "is stopped" ) end) end) cleanup_instance(dir, 'script') - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err)) @@ -132,19 +168,21 @@ do local status, err = pcall(function() test:test("basic test for bad script", function(test_i) test_i:plan(8) - check_ok(test_i, dir, 'start', 'script', 65280, nil, + check_ok(test_i, dir, 'start', 'script', 1, nil, 'Instance script is not found') - check_ok(test_i, dir, 'start', 'bad_script', 0, nil, + check_ok(test_i, dir, 'start', 'bad_script', 1, nil, 'unexpected symbol near') check_ok(test_i, dir, 'start', 'good_script', 0) - check_ok(test_i, dir, 'eval', 'good_script bad_script.lua', 256, - nil, 'Failed to check instance file') + fiber.sleep(0.1) + -- wait here + check_ok(test_i, dir, 'eval', 'good_script bad_script.lua', 3, + nil, 'Error, while reloading config:') check_ok(test_i, dir, 'stop', 'good_script', 0) end) end) cleanup_instance(dir, 'good_script') - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err)) @@ -167,8 +205,9 @@ do test:test("check answers in case of call", function(test_i) test_i:plan(6) check_ok(test_i, dir, 'start', 'good_script', 0) - check_ok(test_i, dir, 'eval', 'good_script bad_script.lua', 768, - nil, 'Error, while reloading config') + fiber.sleep(0.1) + check_ok(test_i, dir, 'eval', 'good_script bad_script.lua', 3, nil, + 'Error, while reloading config') check_ok(test_i, dir, 'eval', 'good_script ok_script.lua', 0, '---\n- 1\n...', nil) check_ok(test_i, dir, 'stop', 'good_script', 0) @@ -176,7 +215,7 @@ do end) cleanup_instance(dir, 'good_script') - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err)) @@ -211,7 +250,7 @@ do end) end) - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err)) @@ -224,7 +263,7 @@ do local dir = fio.tempdir() local filler_code = [[ - box.cfg{slab_alloc_arena = 0.1} + box.cfg{slab_alloc_arena = 0.1, background=false} local space = box.schema.create_space("test") space:create_index("primary") space:insert({[1] = 1, [2] = 2, [3] = 3, [4] = 4}) @@ -235,11 +274,11 @@ do space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) os.exit(0) ]] - local command_base = 'tarantoolctl cat filler/00000000000000000000.xlog' create_script(dir, 'filler.lua', filler_code) local function check_ctlcat(test, dir, args, delim, lc) + local command_base = 'tarantoolctl cat filler/00000000000000000000.xlog' local desc = args and "cat + " .. args or "cat" args = args and " " .. args or "" local res, stdout, stderr = run_command(dir, command_base .. args) @@ -261,7 +300,7 @@ do end) end) - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err)) @@ -300,12 +339,15 @@ do local remote_path = create_script(dir, 'remote.lua', remote_code) test_run:cmd(("create server remote with script='%s'"):format(remote_path)) test_run:cmd("start server remote") - local port = tonumber(test_run:eval("remote", "return require('uri').parse(box.cfg.listen).service")[1]) + local port = tonumber( + test_run:eval("remote", + "return require('uri').parse(box.cfg.listen).service")[1] + ) local command_base = ('tarantoolctl play localhost:%d filler/00000000000000000000.xlog'):format(port) local status, err = pcall(function() - test:test("fill and test cat output", function(test_i) + test:test("fill and test play output", function(test_i) test_i:plan(6) check_ok(test_i, dir, 'start', 'filler', 0) fiber.sleep(0.01) @@ -322,7 +364,7 @@ do test_run:cmd("stop server remote") test_run:cmd("cleanup server remote") - fio.rmdir(dir) + recursive_rmdir(dir) if status == false then print(("Error: %s"):format(err))