Skip to content

server: fix grep_log not finding string logged immediately before #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/package_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- dist: fedora
version: 36

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Check out repo
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login != 'tarantool'
strategy:
matrix:
tarantool: ["1.10", "2.6", "2.7", "2.8", "2.10", "2.11", "3.0"]
tarantool: ["2.11", "3.0", "3.1", "3.2", "3.3", "3.4"]
fail-fast: false
runs-on: [ubuntu-20.04]
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@master
- uses: tarantool/setup-tarantool@v3
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Fixed a bug when `server:grep_log()` failed to find a string logged in
`server:exec()` called immediately before it (gh-421).

## 1.1.0

- Added logging to unified file (gh-324).
Expand Down
23 changes: 22 additions & 1 deletion luatest/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,19 @@ function Server:grep_log(pattern, bytes_num, opts)
fail('Failed to open log file')
end

io.flush() -- attempt to flush stdout == log fd
-- Logs written by a test server go through a pipe and are processed
-- by a luatest fiber before they make it to the log file. Let's write
-- a unique marker string to the server log via server:exec() and retry
-- until we find the marker.
local marker
if self ~= nil and self.net_box ~= nil and self.net_box:ping() then
marker = ('LUATEST_GREP_LOG_MARKER:%d'):format(math.random(1e9))
self:exec(function(s) require('log').info(s) end, {marker})
end

local retries = 0

::retry::
local filesize = file:seek(0, 'SEEK_END')
if filesize == nil then
fail('Failed to get log file size')
Expand Down Expand Up @@ -938,11 +949,21 @@ function Server:grep_log(pattern, bytes_num, opts)
else
found = string.match(line, pattern) or found
end
if marker ~= nil and string.match(line, marker) then
marker = nil
end
end
pos = endpos and endpos + 2 -- jump to char after \n
until pos == nil
until s == ''

if found == nil and marker ~= nil and retries < 10 then
log.info('Retrying grep because marker was not found')
retries = retries + 1
fiber.sleep(0.1)
goto retry
end

file:close()

return found
Expand Down
6 changes: 3 additions & 3 deletions test/luaunit/assertions_error_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ function g.test_assert_errorCovers()
t.assert_error_covers({type = 'ClientError', code = 0}, box.error, 0)
local err = box.error.new(box.error.UNKNOWN)
if err.set_prev ~= nil then
err:set_prev(box.error.new(box.error.ILLEGAL_PARAMS, 'foo'))
err:set_prev(box.error.new(box.error.UNSUPPORTED, 'foo', 'bar'))
expected = {
type = 'ClientError',
code = box.error.UNKNOWN,
prev = {code = box.error.ILLEGAL_PARAMS}
prev = {type = 'ClientError', code = box.error.UNSUPPORTED}
}
t.assert_error_covers(expected, err.raise, err)
t.assert_error_covers(expected, box.error, err)
end

-- test assert failure due to unexpected error trace
Expand Down
Loading