diff --git a/CHANGELOG.md b/CHANGELOG.md index da4a89c..fb5065a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/luatest/replica_set.lua b/luatest/replica_set.lua index 101c1d0..f9b697a 100644 --- a/luatest/replica_set.lua +++ b/luatest/replica_set.lua @@ -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. diff --git a/luatest/runner.lua b/luatest/runner.lua index 17eba90..2a282ff 100644 --- a/luatest/runner.lua +++ b/luatest/runner.lua @@ -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') @@ -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) @@ -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 @@ -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 diff --git a/luatest/server.lua b/luatest/server.lua index 10c896d..f57e0a2 100644 --- a/luatest/server.lua +++ b/luatest/server.lua @@ -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 diff --git a/test/server_test.lua b/test/server_test.lua index 0376217..008e7f1 100644 --- a/test/server_test.lua +++ b/test/server_test.lua @@ -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))