diff --git a/luatest/runner.lua b/luatest/runner.lua index b855645..e4ce6b1 100644 --- a/luatest/runner.lua +++ b/luatest/runner.lua @@ -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 @@ -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) diff --git a/luatest/server.lua b/luatest/server.lua index b82c556..cf75469 100644 --- a/luatest/server.lua +++ b/luatest/server.lua @@ -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: , 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`).