Skip to content

Commit ab9aad4

Browse files
test: fix flaky cached schema case
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
1 parent 2920966 commit ab9aad4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,10 @@ where:
17391739
vshard router instance. Set this parameter if your space is not
17401740
a part of the default vshard cluster
17411741
* `cached` (`?boolean`) - if `false`, reloads storages schema on call;
1742-
if `true`, return last known schema; default value is `false`
1742+
if `true`, return last known schema; default value is `false`.
1743+
Beware that consequent calls with `cached=true` do not guarantee
1744+
the same result if schema had chaned since net.box connections
1745+
still may perform reload on internal ping or any other request
17431746

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

test/integration/schema_test.lua

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
local t = require('luatest')
22

3+
local json = require('json')
4+
local luatest_comparator = require('luatest.comparator')
5+
36
local helpers = require('test.helper')
47

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

125+
-- Lazy reimplementation of
126+
-- https://github.com/tarantool/luatest/pull/294
127+
local function assert_one_of(t, actual, expected)
128+
local err_msg = nil
129+
local res = false
130+
for _, v in ipairs(expected) do
131+
if luatest_comparator.equals(actual, v) then
132+
res = true
133+
break
134+
end
135+
if err_msg == nil then
136+
err_msg = ("expected %s to be one of %s"):format(json.encode(expected), json.encode(v))
137+
else
138+
err_msg = err_msg .. " ," .. json.encode(v)
139+
end
140+
end
141+
if not res then
142+
t.fail(err_msg)
143+
end
144+
end
145+
122146
pgroup.test_schema_cached = function(g)
123147
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
124148
server:call('alter_schema')
125149
end)
126150

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

132158
pgroup.test_schema_reloaded = function(g)

0 commit comments

Comments
 (0)