-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
> What's the problem? When creating the logic for saving artifacts [1] a global variable has been created as `current_test` in the `runner.lua` module. Luatest has collected all the tests and runs a simple loop. At the beginning of each iteration the current test is written to the `current_test'. Server saved the value of the current test. However at some point the current test in the global variable and in the server object were different (the server stored information about the previous test). Also server does not store information about which test it was used in. > What is the solution? Redesign the logic of working with artifacts: now each test knows which server is linked to it, and each server knows about the test. For example: foo = Server:new() foo:start() -- only `foo` artifacts g.test_with_foo = function() foo:exec(...) end -- no server artifacts g.test_without_servers = function() ... end [1] #296 Helped-by: Igor Munkin <imun@tarantool.org> Close #299
- Loading branch information
Showing
12 changed files
with
344 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
local t = require('luatest') | ||
local utils = require('luatest.utils') | ||
|
||
local g = t.group() | ||
local Server = t.Server | ||
|
||
g.public = Server:new({ alias = 'public'}) | ||
g.public:start() | ||
|
||
g.test_servers_not_added_if_they_are_not_used = function() | ||
end | ||
|
||
g.after_test('test_servers_not_added_if_they_are_not_used', function() | ||
t.fail_if( | ||
utils.table_len(rawget(_G, 'current_test').value.servers) ~= 0, | ||
'Test instance should not contain a servers') | ||
end) | ||
|
||
g.test_only_public_server_has_been_added = function() | ||
g.public:get_vclock() | ||
end | ||
|
||
g.after_test('test_only_public_server_has_been_added', function() | ||
t.fail_if( | ||
rawget(_G, 'current_test').value.servers[g.public.id] == nil, | ||
'Test should contain only public server') | ||
end) | ||
|
||
|
||
g.test_only_private_server_has_been_added = function() | ||
g.private = Server:new({alias = 'private'}) | ||
g.private:start() | ||
end | ||
|
||
g.after_test('test_only_private_server_has_been_added', function() | ||
t.fail_if( | ||
rawget(_G, 'current_test').value.servers[g.private.id] == nil, | ||
'Test should contain only private server') | ||
|
||
end) | ||
|
||
g.before_test('test_add_server_from_test_hooks', function() | ||
g.before = Server:new({ alias = 'before' }) | ||
g.before:start() | ||
end) | ||
|
||
g.test_add_server_from_test_hooks = function() | ||
end | ||
|
||
g.after_test('test_add_server_from_test_hooks', function() | ||
g.after = Server:new({ alias = 'after' }) | ||
g.after:start() | ||
|
||
local test_servers = rawget(_G, 'current_test').value.servers | ||
|
||
t.fail_if( | ||
utils.table_len(test_servers) ~= 2, | ||
'Test should contain two servers (from before/after hooks)') | ||
t.fail_if( | ||
test_servers[g.before.id] == nil or | ||
test_servers[g.after.id] == nil, | ||
'Test should contain only `before` and `after` servers') | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local t = require('luatest') | ||
local utils = require('luatest.utils') | ||
|
||
local Server = t.Server | ||
|
||
local g = t.group() | ||
|
||
g.test_foo = function() | ||
g.foo_test = rawget(_G, 'current_test').value | ||
end | ||
|
||
g.test_bar = function() | ||
g.bar_test = rawget(_G, 'current_test').value | ||
end | ||
|
||
g.after_all(function() | ||
g.s = Server:new() | ||
g.s:start() | ||
|
||
t.fail_if( | ||
utils.table_len(g.foo_test.servers) ~= 0, | ||
'Test instance `foo` should not contain a servers') | ||
|
||
t.fail_if( | ||
utils.table_len(g.bar_test.servers) ~= 0, | ||
'Test instance `bar` should not contain a servers') | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local t = require('luatest') | ||
local utils = require('luatest.utils') | ||
local fio = require('fio') | ||
|
||
local g = t.group() | ||
local Server = t.Server | ||
|
||
local function is_server_in_test(server, test) | ||
for _, s in pairs(test.servers) do | ||
if server.id == s.id then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
g.public = Server:new({alias = 'public'}) | ||
g.public:start() | ||
|
||
g.before_all(function() | ||
g.all = Server:new({alias = 'all9'}) | ||
g.all:start() | ||
end) | ||
|
||
g.before_each(function() | ||
g.each = Server:new({alias = 'each'}) | ||
g.each:start() | ||
end) | ||
|
||
g.before_test('test_association_between_test_and_servers', function() | ||
g.test = Server:new({alias = 'test'}) | ||
g.test:start() | ||
end) | ||
|
||
|
||
g.test_association_between_test_and_servers = function() | ||
g.internal = Server:new({alias = 'internal'}) | ||
g.internal:start() | ||
|
||
local test = rawget(_G, 'current_test').value | ||
|
||
-- test static association | ||
t.assert(is_server_in_test(g.internal, test)) | ||
t.assert(is_server_in_test(g.each, test)) | ||
t.assert(is_server_in_test(g.test, test)) | ||
t.assert_not(is_server_in_test(g.public, test)) | ||
|
||
g.public:exec(function() return 1 + 1 end) | ||
g.all:exec(function() return 1 + 1 end) | ||
|
||
-- test dynamic association | ||
t.assert(is_server_in_test(g.public, test)) | ||
t.assert(is_server_in_test(g.all, test)) | ||
|
||
t.assert(utils.table_len(test.servers) == 5) | ||
end | ||
|
||
g.after_test('test_association_between_test_and_servers', function() | ||
g.test:drop() | ||
t.assert(fio.path.exists(g.test.artifacts)) | ||
end) | ||
|
||
g.after_each(function() | ||
g.each:drop() | ||
t.assert(fio.path.exists(g.each.artifacts)) | ||
end) | ||
|
||
g.after_all(function() | ||
g.all:drop() | ||
t.assert(fio.path.exists(g.all.artifacts)) | ||
end) |
Oops, something went wrong.