Skip to content

Commit

Permalink
test: fix flaky cached schema case
Browse files Browse the repository at this point in the history
We cannot guarantee that cached schema is always the old one since
net.box may reload the schema, see [1] for example of fail.

1. https://github.com/tarantool/crud/actions/runs/6531939885/job/17734151700
  • Loading branch information
DifferentialOrange committed Oct 16, 2023
1 parent 2920966 commit ab9aad4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,10 @@ where:
vshard router instance. Set this parameter if your space is not
a part of the default vshard cluster
* `cached` (`?boolean`) - if `false`, reloads storages schema on call;
if `true`, return last known schema; default value is `false`
if `true`, return last known schema; default value is `false`.
Beware that consequent calls with `cached=true` do not guarantee
the same result if schema had chaned since net.box connections
still may perform reload on internal ping or any other request

Returns space schema (or spaces schema map), error.

Expand Down
28 changes: 27 additions & 1 deletion test/integration/schema_test.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local t = require('luatest')

local json = require('json')
local luatest_comparator = require('luatest.comparator')

local helpers = require('test.helper')

local pgroup = t.group('schema', helpers.backend_matrix({
Expand Down Expand Up @@ -119,14 +122,37 @@ pgroup.test_timeout_option = function(g)
t.assert_equals(err, nil)
end

-- Lazy reimplementation of
-- https://github.com/tarantool/luatest/pull/294
local function assert_one_of(t, actual, expected)
local err_msg = nil
local res = false
for _, v in ipairs(expected) do
if luatest_comparator.equals(actual, v) then
res = true
break
end
if err_msg == nil then
err_msg = ("expected %s to be one of %s"):format(json.encode(expected), json.encode(v))
else
err_msg = err_msg .. " ," .. json.encode(v)
end
end
if not res then
t.fail(err_msg)
end
end

pgroup.test_schema_cached = function(g)
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
server:call('alter_schema')
end)

-- We cannot guarantee net.box hadn't reloaded the schema, so
-- it's either old or new.
local result_after, err = g.router:call('crud.schema', {nil, {cached = true}})
t.assert_equals(err, nil)
t.assert_equals(result_after, expected_schema())
assert_one_of(t, result_after, {expected_schema(), altered_schema()})
end

pgroup.test_schema_reloaded = function(g)
Expand Down

0 comments on commit ab9aad4

Please sign in to comment.