Skip to content

Commit

Permalink
server: fix reset option in grep_log for Tarantool EE
Browse files Browse the repository at this point in the history
server.grep_log() has 'reset' option, which allows to reset the result,
when instance restart is found. It doesn't work on Tarantool EE, as
it tries to find "Tarantool %d+.%d+.%d+-.*%d+-g.*" pattern, but EE
has "Tarantool Enterprise ...".

Let's use tarantool.package value instead of explicitly specifying,
on which tarantool package restart is done.

Closes #319
  • Loading branch information
Serpentian authored and ylobankov committed Aug 25, 2023
1 parent 3f13533 commit 3fa719d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local http_client = require('http.client')
local json = require('json')
local log = require('log')
local net_box = require('net.box')
local tarantool = require('tarantool')
local uri = require('uri')
local _, luacov_runner = pcall(require, 'luacov.runner') -- luacov may not be installed

Expand Down Expand Up @@ -722,7 +723,8 @@ function Server:grep_log(pattern, bytes_num, opts)
line = table.concat(buf)
buf = nil
end
if string.match(line, '> Tarantool %d+.%d+.%d+-.*%d+-g.*$') and reset then
local package = tarantool.package or 'Tarantool'
if string.match(line, '> ' .. package .. ' %d+.%d+.%d+-.*%d+-g.*$') and reset then
found = nil -- server was restarted, reset the result
else
found = string.match(line, pattern) or found
Expand Down
23 changes: 22 additions & 1 deletion test/server_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ local command = fio.pathjoin(root, 'test', 'server_instance.lua')
local server = Server:new({
command = command,
workdir = fio.pathjoin(datadir, 'common'),
env = {custom_env = 'test_value'},
env = {
TARANTOOL_LOG = fio.pathjoin(datadir, 'server_test.log'),
custom_env = 'test_value',
},
http_port = 8182,
net_box_port = 3133,
})
Expand Down Expand Up @@ -476,3 +479,21 @@ end
g.after_test('test_error_level_is_correct', function()
g.s:drop()
end)

g.test_grep_log = function()
server:connect_net_box()

-- Test that grep_log just works.
server:exec(function() require('log').info('test grep_log') end)
t.assert(server:grep_log('test grep_log'))

-- By default opts.reset in server:grep_log() is true, so we
-- should not find the message after instance restart.
server:restart()
t.helpers.retrying({}, function() server:http_request('get', '/ping') end)
server:connect_net_box()
t.assert_not(server:grep_log('test grep_log'))

server.net_box:close()
server.net_box = nil
end

0 comments on commit 3fa719d

Please sign in to comment.