Skip to content

Commit 9c7710e

Browse files
Oleg Chaplashkinylobankov
Oleg Chaplashkin
authored andcommitted
Save artifacts only once
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
1 parent 18859f6 commit 9c7710e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Diff for: luatest/runner.lua

+5-7
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ function Runner.mt:update_status(node, err)
338338
elseif err.status == 'fail' or err.status == 'error' or err.status == 'skip'
339339
or err.status == 'xfail' or err.status == 'xsuccess' then
340340
node:update_status(err.status, err.message, err.trace)
341+
if utils.table_len(node.servers) > 0 then
342+
for _, server in pairs(node.servers) do
343+
server:save_artifacts()
344+
end
345+
end
341346
else
342347
error('No such status: ' .. pp.tostring(err.status))
343348
end
@@ -458,13 +463,6 @@ end
458463
function Runner.mt:invoke_test_function(test)
459464
local err = self:protected_call(test.group, test.method, test.name)
460465
self:update_status(test, err)
461-
if not test:is('success') then
462-
if utils.table_len(test.servers) > 0 then
463-
for _, server in pairs(test.servers) do
464-
server:save_artifacts()
465-
end
466-
end
467-
end
468466
end
469467

470468
function Runner.mt:find_test(groups, name)

Diff for: luatest/server.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,20 @@ function Server:restart(params, opts)
372372
end
373373

374374
-- Save server artifacts by copying the working directory.
375-
-- Throws an error when the copying is not successful.
375+
-- The save logic will only work once to avoid overwriting the artifacts directory.
376+
-- If an error occurred, then the server artifacts path will be replaced by the
377+
-- following string: `Failed to copy artifacts for server (alias: <alias>, workdir: <workdir>)`.
376378
function Server:save_artifacts()
379+
if self.artifacts_saved then
380+
return
381+
end
377382
local ok, err = fio.copytree(self.workdir, self.artifacts)
378383
if not ok then
379-
log.error(('Failed to copy artifacts for server (alias: %s, workdir: %s): %s')
380-
:format(self.alias, fio.basename(self.workdir), err))
384+
self.artifacts = ('Failed to copy artifacts for server (alias: %s, workdir: %s)')
385+
:format(self.alias, fio.basename(self.workdir))
386+
log.error(('%s: %s'):format(self.artifacts, err))
381387
end
388+
self.artifacts_saved = true
382389
end
383390

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

0 commit comments

Comments
 (0)