Skip to content
Snippets Groups Projects
Commit 02e2b292 authored by Gleb Kashkin's avatar Gleb Kashkin Committed by Igor Munkin
Browse files

test: update compat options tests with server:exec

Before the change all tarantool.compat options' tests were running on
the same instance, and because luatest uses multiple threads, they could
interfere with compat configuration at the same time as other test
checks default behavior. This could cause such tests to flack.

Now all options' tests are being run in a separate instance via
server:exec().

Closes #8033

NO_DOC=test fix
NO_CHANGELOG=test fix
parent a24714c5
No related branches found
No related tags found
No related merge requests found
local compat = require('tarantool').compat
local yaml = require('yaml')
local server = require('luatest.server')
local t = require('luatest')
local g = t.group()
g.test_encode = function()
local function server_test_encode()
local compat = require('tarantool').compat
local yaml = require('yaml')
local t = require('luatest')
local str = 'Title: xxx\n - Item 1\n - Item 2\n'
local old_res = '--- "Title: xxx\\n - Item 1\\n - Item 2\\n"\n...\n'
local new_res = '--- |\n Title: xxx\n - Item 1\n - Item 2\n...\n'
......@@ -15,3 +18,10 @@ g.test_encode = function()
t.assert_equals(yaml.encode(str), old_res)
compat.yaml_pretty_multiline = 'default'
end
g.test_encode = function()
g.server = server:new{alias = 'default'}
g.server:start()
g.server:exec(server_test_encode)
g.server:stop()
end
local compat = require('tarantool').compat
local json = require('json')
local popen = require('popen')
local clock = require('clock')
local server = require('luatest.server')
local t = require('luatest')
local g = t.group()
g.test_json_encode = function()
local function server_test_json_encode()
local compat = require('tarantool').compat
local json = require('json')
local t = require('luatest')
-- Test that '/' is escaped with default setting.
t.assert_equals(json.encode({url = 'https://srv:7777'}),
'{"url":"https:\\/\\/srv:7777"}')
......@@ -44,7 +44,11 @@ g.test_json_encode = function()
[["\/home\/user\/tarantool"]])
end
g.test_json_new_encode = function()
local function server_test_json_new_encode()
local compat = require('tarantool').compat
local json = require('json')
local t = require('luatest')
compat.json_escape_forward_slash = 'old'
-- Test that '/' is escaped with 'old' setting.
t.assert_equals(json.encode('/'), [["\/"]])
......@@ -67,7 +71,11 @@ end
-- log.info in json format mode uses internal encoder that takes msgpuck
-- char2escape table, while mp_char2escape is changed by compat.
g.test_mp_encode = function()
local function popen_test_mp_encode()
local popen = require('popen')
local clock = require('clock')
local t = require('luatest')
-- Start external tarantool session.
local TARANTOOL_PATH = arg[-1]
local cmd = TARANTOOL_PATH .. ' -i 2>&1'
......@@ -117,3 +125,18 @@ g.test_mp_encode = function()
ph:close()
end
local tests = {
server_test_json_encode,
server_test_json_new_encode,
popen_test_mp_encode,
}
local g = t.group('pgroup', t.helpers.matrix{test_func = tests})
g.test_json_encode = function(cg)
local s = server:new{alias = 'default'}
s:start()
s:exec(cg.params.test_func)
s:stop()
end
local compat = require('tarantool').compat
local server = require('luatest.server')
local t = require('luatest')
local g = t.group()
local fiber = require('fiber')
g.test_channel_close_default = function()
local function server_test_channel_close_default()
local fiber = require('fiber')
local t = require('luatest')
-- No graceful close (old) by default.
local ch = fiber.channel(10)
ch:put('one')
......@@ -15,48 +16,40 @@ g.test_channel_close_default = function()
t.assert_equals(ch:get(), nil)
end
g.test_channel_close_old = function()
compat.fiber_channel_close_mode = 'old'
local ch = fiber.channel(10)
ch:put('one')
ch:put('two')
t.assert_equals(ch:get(), 'one')
ch:close()
t.assert(ch:is_closed())
t.assert_not(ch:put('three'))
t.assert_equals(ch:get(), nil)
end
local function server_test_channel_close(mode)
local compat = require('tarantool').compat
local fiber = require('fiber')
local t = require('luatest')
g.test_channel_close_new = function()
-- Graceful close (new) selected.
compat.fiber_channel_close_mode = 'new'
compat.fiber_channel_close_mode = mode
local ch = fiber.channel(10)
ch:put('one')
ch:put('two')
ch:put('three')
t.assert_equals(ch:get(), 'one')
ch:close()
t.assert(ch:is_closed())
t.assert_not(ch:put('three'))
t.assert_not(ch:put('four'))
t.assert_equals(ch:get(), 'one')
t.assert(ch:is_closed())
if mode == 'new' then
t.assert_equals(ch:get(), 'two')
t.assert(ch:is_closed())
t.assert_equals(ch:get(), 'two')
t.assert(ch:is_closed())
t.assert_equals(ch:get(), 'three')
t.assert(ch:is_closed())
end
t.assert_equals(ch:get(), nil)
end
g.test_close_graceful_on_empty = function()
compat.fiber_channel_close_mode = 'new'
local ch = fiber.channel(10)
ch:put('one')
ch:get()
ch:close()
t.assert(ch:is_closed())
end
local server_test_close_reader_payload = function(mode)
local compat = require('tarantool').compat
local fiber = require('fiber')
local t = require('luatest')
local test_close_reader_payload = function(mode)
compat.fiber_channel_close_mode = mode
local ch = fiber.channel(0)
local reader = fiber.new(function()
......@@ -86,15 +79,11 @@ local test_close_reader_payload = function(mode)
t.assert(status, err)
end
g.test_close_reader_old = function()
test_close_reader_payload('old')
end
g.test_close_reader_new = function()
test_close_reader_payload('new')
end
local server_test_close_writer_payload = function(mode)
local compat = require('tarantool').compat
local fiber = require('fiber')
local t = require('luatest')
local test_close_writer_payload = function(mode)
compat.fiber_channel_close_mode = mode
local ch = fiber.channel(0)
local writer = fiber.new(function()
......@@ -124,10 +113,19 @@ local test_close_writer_payload = function(mode)
t.assert(status, err)
end
g.test_close_writer_old = function()
test_close_writer_payload('old')
end
local tests = {
server_test_channel_close,
server_test_channel_close_default,
server_test_close_writer_payload,
server_test_close_reader_payload,
}
local g = t.group('pgroup', t.helpers.matrix{test_func = tests,
mode = {'new', 'old'}})
g.test_close_writer_new = function()
test_close_writer_payload('new')
g.test_fiber_close = function(cg)
local s = server:new{alias = 'default'}
s:start()
s:exec(cg.params.test_func, {cg.params.mode})
s:stop()
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment