Skip to content

Commit

Permalink
Save server artifacts once regardless of calls
Browse files Browse the repository at this point in the history
Due to the specifics of working with the test and the added connection
between `test <-> server` as well as because artifacts will be saved
with a connection problem [1], the `Server:save_artifacts()` method were
called more than once. In case of any problems we could overwrite already
saved artifacts. Added a flag that will ensure that the saving will be
executed only once.

There was also a problem when copying artifacts was not performed but the
path to the artifacts was formed as a directory with artifacts (as if it
exists):

    artifacts:
        server -> /tmp/t/artifacts/server-XXX

And if we try to look at these artifacts, nothing will work:

    $ ls -la /tmp/t/artifacts/server-XXX
    ls: cannot access '/tmp/t/artifacts/server-XXX': No such file or
    directory

To show explicitly that the saving failed with an error, the string will
now be written to the artifacts:

    artifacts:
        server -> Failed to copy artifacts for server (workdir:
        /tmp/t/artifacts/server-XXX)

[1] tarantool/luatest@251b35f

Close tarantool#304
  • Loading branch information
Oleg Chaplashkin committed Oct 2, 2023
1 parent 18859f6 commit ae9f463
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 5 additions & 7 deletions luatest/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ function Runner.mt:update_status(node, err)
elseif err.status == 'fail' or err.status == 'error' or err.status == 'skip'
or err.status == 'xfail' or err.status == 'xsuccess' then
node:update_status(err.status, err.message, err.trace)
if utils.table_len(node.servers) > 0 then
for _, server in pairs(node.servers) do
server:save_artifacts()
end
end
else
error('No such status: ' .. pp.tostring(err.status))
end
Expand Down Expand Up @@ -458,13 +463,6 @@ end
function Runner.mt:invoke_test_function(test)
local err = self:protected_call(test.group, test.method, test.name)
self:update_status(test, err)
if not test:is('success') then
if utils.table_len(test.servers) > 0 then
for _, server in pairs(test.servers) do
server:save_artifacts()
end
end
end
end

function Runner.mt:find_test(groups, name)
Expand Down
15 changes: 11 additions & 4 deletions luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,21 @@ function Server:restart(params, opts)
log.debug('Restarted server PID: ' .. self.process.pid)
end

-- Save server artifacts by copying the working directory.
-- Throws an error when the copying is not successful.
--- Save server artifacts by copying the working directory.
-- The save logic will only work once to avoid overwriting the artifacts directory.
-- If an error occurred, then server artifacts path will be replaced follow string:
-- `Failed to copy artifacts for server (alias: <alias>, workdir: <workdir>)`.
function Server:save_artifacts()
if self.is_artifacts_handled then
return
end
local ok, err = fio.copytree(self.workdir, self.artifacts)
if not ok then
log.error(('Failed to copy artifacts for server (alias: %s, workdir: %s): %s')
:format(self.alias, fio.basename(self.workdir), err))
self.artifacts = ('Failed to copy artifacts for server (alias: %s, workdir: %s)')
:format(self.alias, fio.basename(self.workdir))
log.error(('%s: %s'):format(self.artifacts, err))
end
self.is_artifacts_handled = true
end

-- Wait until the given condition is `true` (anything except `false` and `nil`).
Expand Down

0 comments on commit ae9f463

Please sign in to comment.