File: fail_main.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (39 lines) | stat: -rwxr-xr-x 1,127 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env tarantool

local tap = require('tap')
local test = tap.test("fail_main")
local fio = require('fio')
local tarantool_bin = arg[-1]

test:plan(1)

function run_script(code)
    local dir = fio.tempdir()
    local script_path = fio.pathjoin(dir, 'script.lua')
    local script = fio.open(script_path, {'O_CREAT', 'O_WRONLY', 'O_APPEND'},
        tonumber('0777', 8))
    script:write(code)
    script:close()
    local output_file = fio.pathjoin(fio.cwd(), 'out.txt')
    local cmd = [[/bin/sh -c 'cd "%s" && "%s" ./script.lua 0> %s 2> %s']]
    local code = os.execute(
        string.format(cmd, dir, tarantool_bin, output_file, output_file)
    )
    fio.rmtree(dir)
    local out_fd = fio.open(output_file, {'O_RDONLY'})
    local output = out_fd:read(100000)
    out_fd:close()
    return code, output
end

--
-- gh-4382: an error in main script should be handled gracefully,
-- with proper logging.
--
local code, output = run_script("error('Error in the main script')")

test:ok(output:match("fatal error, exiting the event loop"),
        "main script error is handled gracefully")

test:check()
os.exit(0)