Skip to content

Commit 18859f6

Browse files
Oleg Chaplashkinylobankov
Oleg Chaplashkin
authored andcommitted
Not delete server's workdir in Server:drop()
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 #308
1 parent a188577 commit 18859f6

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- Save server artifacts (logs, snapshots, etc.) if the test fails.
5353
- Group working directories of servers inside a replica set into one directory.
5454
- Fix collecting coverage if tarantool binary has a suffix.
55+
- Add `--no-clean` option to disable deletion of the var directory.
5556

5657
## 0.5.7
5758

luatest/replica_set.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,16 @@ function ReplicaSet:stop()
183183
end
184184
end
185185

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

194198
--- Get a server which is a writable node in the replica set.

luatest/runner.lua

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local GenericOutput = require('luatest.output.generic')
1212
local hooks = require('luatest.hooks')
1313
local loader = require('luatest.loader')
1414
local pp = require('luatest.pp')
15+
local Server = require('luatest.server')
1516
local sorted_pairs = require('luatest.sorted_pairs')
1617
local TestInstance = require('luatest.test_instance')
1718
local utils = require('luatest.utils')
@@ -107,6 +108,8 @@ Options:
107108
May be repeated to exclude several patterns
108109
Make sure you escape magic chars like +? with %
109110
--coverage: Use luacov to collect code coverage.
111+
--no-clean: Disable the var directory (default: /tmp/t) deletion before
112+
running tests.
110113
]]
111114

112115
function Runner.parse_cmd_line(args)
@@ -170,6 +173,8 @@ function Runner.parse_cmd_line(args)
170173
result.enable_capture = false
171174
elseif arg == '--coverage' then
172175
result.coverage_report = true
176+
elseif arg == '--no-clean' then
177+
result.no_clean = true
173178
elseif arg:sub(1,1) == '-' then
174179
error('Unknown option: ' .. arg)
175180
elseif arg:find('/') then
@@ -273,10 +278,17 @@ function Runner.mt:bootstrap()
273278
self.groups = self.luatest.groups
274279
end
275280

281+
function Runner.mt:cleanup()
282+
if not self.no_clean then
283+
fio.rmtree(Server.vardir)
284+
end
285+
end
286+
276287
function Runner.mt:run()
277288
self:bootstrap()
278289
local filtered_list = self.class.filter_tests(self:find_tests(), self.tests_pattern)
279290
self:start_suite(#filtered_list[true], #filtered_list[false])
291+
self:cleanup()
280292
self:run_tests(filtered_list[true])
281293
self:end_suite()
282294
if self.result.aborted then

luatest/server.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,16 @@ function Server:stop()
438438
end
439439
end
440440

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

446-
fio.rmtree(self.workdir)
447-
448451
self.instance_id = nil
449452
self.instance_uuid = nil
450453
end

test/replica_set_test.lua

-18
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,6 @@ g.test_save_rs_artifacts_when_server_workdir_passed = function()
8989

9090
end
9191

92-
g.before_test('test_remove_rs_artifacts_when_test_success', function()
93-
g.rs:build_and_add_server({alias = 'replica1', box_cfg = g.box_cfg})
94-
g.rs:build_and_add_server({alias = 'replica2', box_cfg = g.box_cfg})
95-
g.rs:build_and_add_server({alias = 'replica3', box_cfg = g.box_cfg})
96-
g.rs:start()
97-
98-
g.rs_artifacts = ('%s/artifacts/%s'):format(Server.vardir, g.rs.id)
99-
g.s1_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica1').id)
100-
g.s2_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica2').id)
101-
g.s3_artifacts = ('%s/%s'):format(g.rs_artifacts, g.rs:get_server('replica3').id)
102-
end)
103-
104-
g.test_remove_rs_artifacts_when_test_success = function()
105-
g.rs:drop()
106-
107-
t.assert_equals(fio.path.exists(g.rs.workdir), false)
108-
end
109-
11092
g.test_rs_no_socket_collision_with_custom_alias = function()
11193
local s1 = g.rs:build_server({alias = 'foo'})
11294
local s2 = g.rs:build_server({alias = 'bar'})

test/server_test.lua

-8
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,6 @@ g.test_save_server_artifacts_when_test_failed = function()
373373
t.assert_equals(fio.path.is_dir(s2_artifacts), true)
374374
end
375375

376-
g.test_remove_server_artifacts_when_test_success = function()
377-
local s = Server:new()
378-
s:start()
379-
s:drop()
380-
381-
t.assert_equals(fio.path.exists(s.workdir), false)
382-
end
383-
384376
g.test_server_build_listen_uri = function()
385377
local uri = Server.build_listen_uri('foo')
386378
t.assert_equals(uri, ('%s/foo.sock'):format(Server.vardir))

0 commit comments

Comments
 (0)