Skip to content
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
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