Skip to content

Commit

Permalink
Save artifacts only once
Browse files Browse the repository at this point in the history
Since commit [1] the `Server:save_artifacts()` function was called more
than once. Due to this fact 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:

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

And if we tried to look at these artifacts, we could see this:

    $ 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 following
string will now be written to the artifacts:

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

[1] 251b35f

Part of #304
  • Loading branch information
Oleg Chaplashkin committed Oct 6, 2023
1 parent 18859f6 commit 90d9ae8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 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
13 changes: 10 additions & 3 deletions luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,20 @@ function Server:restart(params, opts)
end

-- Save server artifacts by copying the working directory.
-- Throws an error when the copying is not successful.
-- The save logic will only work once to avoid overwriting the artifacts directory.
-- If an error occurred, then the server artifacts path will be replaced by the
-- following string: `Failed to copy artifacts for server (alias: <alias>, workdir: <workdir>)`.
function Server:save_artifacts()
if self.artifacts_saved 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.artifacts_saved = true
end

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

0 comments on commit 90d9ae8

Please sign in to comment.