Skip to content

Commit

Permalink
Not delete server's workdir in Server:drop()
Browse files Browse the repository at this point in the history
Now, luatest does not delete the server's working directory in the drop()
function. Instead of this, it deletes the whole var dir (default: /tmp/t)
before running tests. So all server artifacts from all tests are saved
after the run and can be analyzed.

However, you can disable this deletion by specifying the new `--no-clean`
option.

Part of tarantool#308
  • Loading branch information
Oleg Chaplashkin authored and ylobankov committed Sep 14, 2023
1 parent a188577 commit 18859f6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- Save server artifacts (logs, snapshots, etc.) if the test fails.
- Group working directories of servers inside a replica set into one directory.
- Fix collecting coverage if tarantool binary has a suffix.
- Add `--no-clean` option to disable deletion of the var directory.

## 0.5.7

Expand Down
8 changes: 6 additions & 2 deletions luatest/replica_set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,16 @@ function ReplicaSet:stop()
end
end

--- Stop all servers in the replica set and clean their working directories.
--- Stop all servers in the replica set and save their artifacts if the test fails.
-- This function should be used only at the end of the test (`after_test`,
-- `after_each`, `after_all` hooks) to terminate all server processes in
-- the replica set. Besides process termination, it saves the contents of
-- each server working directory to the `<vardir>/artifacts` directory
-- for further analysis if the test fails.
function ReplicaSet:drop()
for _, server in ipairs(self.servers) do
server:drop()
end
fio.rmtree(self.workdir)
end

--- Get a server which is a writable node in the replica set.
Expand Down
12 changes: 12 additions & 0 deletions luatest/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local GenericOutput = require('luatest.output.generic')
local hooks = require('luatest.hooks')
local loader = require('luatest.loader')
local pp = require('luatest.pp')
local Server = require('luatest.server')
local sorted_pairs = require('luatest.sorted_pairs')
local TestInstance = require('luatest.test_instance')
local utils = require('luatest.utils')
Expand Down Expand Up @@ -107,6 +108,8 @@ Options:
May be repeated to exclude several patterns
Make sure you escape magic chars like +? with %
--coverage: Use luacov to collect code coverage.
--no-clean: Disable the var directory (default: /tmp/t) deletion before
running tests.
]]

function Runner.parse_cmd_line(args)
Expand Down Expand Up @@ -170,6 +173,8 @@ function Runner.parse_cmd_line(args)
result.enable_capture = false
elseif arg == '--coverage' then
result.coverage_report = true
elseif arg == '--no-clean' then
result.no_clean = true
elseif arg:sub(1,1) == '-' then
error('Unknown option: ' .. arg)
elseif arg:find('/') then
Expand Down Expand Up @@ -273,10 +278,17 @@ function Runner.mt:bootstrap()
self.groups = self.luatest.groups
end

function Runner.mt:cleanup()
if not self.no_clean then
fio.rmtree(Server.vardir)
end
end

function Runner.mt:run()
self:bootstrap()
local filtered_list = self.class.filter_tests(self:find_tests(), self.tests_pattern)
self:start_suite(#filtered_list[true], #filtered_list[false])
self:cleanup()
self:run_tests(filtered_list[true])
self:end_suite()
if self.result.aborted then
Expand Down
9 changes: 6 additions & 3 deletions luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,16 @@ function Server:stop()
end
end

--- Stop the server and clean its working directory.
--- Stop the server and save its artifacts if the test fails.
-- This function should be used only at the end of the test (`after_test`,
-- `after_each`, `after_all` hooks) to terminate the server process.
-- Besides process termination, it saves the contents of the server
-- working directory to the `<vardir>/artifacts` directory for further
-- analysis if the test fails.
function Server:drop()
self:stop()
self:save_artifacts()

fio.rmtree(self.workdir)

self.instance_id = nil
self.instance_uuid = nil
end
Expand Down
18 changes: 0 additions & 18 deletions test/replica_set_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,6 @@ g.test_save_rs_artifacts_when_server_workdir_passed = function()

end

g.before_test('test_remove_rs_artifacts_when_test_success', function()
g.rs:build_and_add_server({alias = 'replica1', box_cfg = g.box_cfg})
g.rs:build_and_add_server({alias = 'replica2', box_cfg = g.box_cfg})
g.rs:build_and_add_server({alias = 'replica3', box_cfg = g.box_cfg})
g.rs:start()

g.rs_artifacts = ('%s/artifacts/%s'):format(Server.vardir, g.rs.id)
g.s1_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica1').id)
g.s2_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica2').id)
g.s3_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica3').id)
end)

g.test_remove_rs_artifacts_when_test_success = function()
g.rs:drop()

t.assert_equals(fio.path.exists(g.rs.workdir), false)
end

g.test_rs_no_socket_collision_with_custom_alias = function()
local s1 = g.rs:build_server({alias = 'foo'})
local s2 = g.rs:build_server({alias = 'bar'})
Expand Down
8 changes: 0 additions & 8 deletions test/server_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,6 @@ g.test_save_server_artifacts_when_test_failed = function()
t.assert_equals(fio.path.is_dir(s2_artifacts), true)
end

g.test_remove_server_artifacts_when_test_success = function()
local s = Server:new()
s:start()
s:drop()

t.assert_equals(fio.path.exists(s.workdir), false)
end

g.test_server_build_listen_uri = function()
local uri = Server.build_listen_uri('foo')
t.assert_equals(uri, ('%s/foo.sock'):format(Server.vardir))
Expand Down

0 comments on commit 18859f6

Please sign in to comment.