Skip to content

Commit

Permalink
Add --no-clean parameter and dont clean workdir
Browse files Browse the repository at this point in the history
Now luatest will always clear the server vardir (`/tmp/t` by default)
before running tests. You should be specify a new `--no-clean` parameter
to disable this deletion.

Also luatest does not delete the server workdir in the Server:drop().

Part of tarantool#308
  • Loading branch information
Oleg Chaplashkin committed Sep 13, 2023
1 parent a188577 commit a252015
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 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 server vardir.

## 0.5.7

Expand Down
4 changes: 2 additions & 2 deletions luatest/replica_set.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ 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 its artifacts.
-- Use this method at the end of test suite.
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: Do not clean the working directory (/tmp/t).
This is cleared by default.
]]

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
5 changes: 2 additions & 3 deletions luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,12 @@ function Server:stop()
end
end

--- Stop the server and clean its working directory.
--- Stop the server and save its artifacts.
-- Use this method at the end of test suite.
function Server:drop()
self:stop()
self:save_artifacts()

fio.rmtree(self.workdir)

self.instance_id = nil
self.instance_uuid = nil
end
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 a252015

Please sign in to comment.