From abb12c6b936ed455ce6e9b3e414104503f04c4de Mon Sep 17 00:00:00 2001 From: Nikolay Shirokovskiy Date: Thu, 29 May 2025 15:57:41 +0300 Subject: [PATCH 1/3] test: fix luaunit/assertions_error_test for Tarantool 3.2 and newer With Tarantool 3.2 and newer the test fails with: ``` ...luatest/test/luaunit/assertions_error_test.lua:244: Unexpected error trace, expected: {file = "/home/runner/work/luatest/luatest/luatest/assertions.lua", line = 102}, actual: { file = "...k/luatest/luatest/test/luaunit/assertions_error_test.lua", line = 236, } ``` On older Tarantool versions the error trace isn't checked because `tarantool._internal.trace_check_is_required` isn't defined there. Tarantool 3.2 is the first version that defines this internal function. Since `error.raise` used by the test resides in 'builtin/error.lua', stack trace checking is enabled for this function. The problem is `error.raise()` does not change the original error trace while `t.assert_error_covers()` expects the trace to point to the place where `error.raise()` was invoked. Let's use `box.error()` instead so the new error has the expected trace. Also change `box.error.ILLEGAL_PARAMS` to `box.error.UNSUPPORTED` for the check to pass because in Tarantool 3.2 the former was changed to `{type = 'IllegalParams'}`. --- test/luaunit/assertions_error_test.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/luaunit/assertions_error_test.lua b/test/luaunit/assertions_error_test.lua index 381d200..2884cdb 100644 --- a/test/luaunit/assertions_error_test.lua +++ b/test/luaunit/assertions_error_test.lua @@ -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 From 79dbf841d96ce5d0c3594b37066a80a976240dbf Mon Sep 17 00:00:00 2001 From: Vladimir Davydov Date: Thu, 29 May 2025 14:30:02 +0300 Subject: [PATCH 2/3] Run tests and packaging on ubuntu-latest Ubuntu 20.04 is no longer supported by GitHub runners. Note that Tarantool versions < 2.11 are too old and not available on ubuntu-latest so they're removed from the test matrix. Instead we add all Tarantool 3.x versions released so far. --- .github/workflows/package_test.yml | 2 +- .github/workflows/test_on_push.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package_test.yml b/.github/workflows/package_test.yml index 028c039..0ee5b12 100644 --- a/.github/workflows/package_test.yml +++ b/.github/workflows/package_test.yml @@ -19,7 +19,7 @@ jobs: - dist: fedora version: 36 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Check out repo diff --git a/.github/workflows/test_on_push.yaml b/.github/workflows/test_on_push.yaml index 8a7d8ae..607b0a0 100644 --- a/.github/workflows/test_on_push.yaml +++ b/.github/workflows/test_on_push.yaml @@ -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 From 888418c30f4e22a62c8828609825815adadef7dd Mon Sep 17 00:00:00 2001 From: Vladimir Davydov Date: Thu, 29 May 2025 14:23:15 +0300 Subject: [PATCH 3/3] server: fix grep_log not finding string logged immediately before 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 so if grep_log() is called immediately after exec() that writes something to the log it may fail to find the logged string. Let's fix this issue by writing a unique marker string to the server log via exec() and retrying grep_log() until we find the marker. Closes #421 --- CHANGELOG.md | 5 +++++ luatest/server.lua | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546e290..1603b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/luatest/server.lua b/luatest/server.lua index 96b1e40..75e70d2 100644 --- a/luatest/server.lua +++ b/luatest/server.lua @@ -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') @@ -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