[Tarantool-patches] [PATCH 2/3] box: always wait box loading in box.execute()
Alexander Turenko
alexander.turenko at tarantool.org
Wed May 13 01:18:04 MSK 2020
<box_load_and_execute> checks whether box is configured with appropriate
locking and configures it when necessary. However it is not so for
<lbox_execute>. We should replace the former with the latter only when
box is fully loaded.
Follow-up #4231
---
src/box/lua/load_cfg.lua | 20 ++++++++++++---
.../gh-4231-box-execute-locking.test.lua | 25 ++++++++++++++++++-
test/box-tap/suite.cfg | 6 +++++
test/box-tap/suite.ini | 1 +
4 files changed, 48 insertions(+), 4 deletions(-)
create mode 100644 test/box-tap/suite.cfg
diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 0b4a14377..9a7b57cd3 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -538,6 +538,11 @@ local box_cfg_guard_whitelist = {
NULL = true;
};
+-- List of box members that requires full box loading.
+local box_restore_after_full_load_list = {
+ execute = true,
+}
+
local box = require('box')
-- Move all box members except the whitelisted to box_configured
local box_configured = {}
@@ -585,12 +590,13 @@ local function load_cfg(cfg)
-- It also would be counter-intuitive to receive an error from
-- box.cfg({<...>}), but find that box is actually configured.
- -- Restore box members after initial configuration
+ -- Restore box members after initial configuration.
for k, v in pairs(box_configured) do
- box[k] = v
+ if not box_restore_after_full_load_list[k] then
+ box[k] = v
+ end
end
setmetatable(box, nil)
- box_configured = nil
box.cfg = setmetatable(cfg,
{
__newindex = function(table, index)
@@ -624,6 +630,14 @@ local function load_cfg(cfg)
box.schema.upgrade{auto = true}
end
+ -- Restore box members that requires full box loading.
+ for k, v in pairs(box_configured) do
+ if box_restore_after_full_load_list[k] then
+ box[k] = v
+ end
+ end
+ box_configured = nil
+
box_is_configured = true
end
box.cfg = locked(load_cfg)
diff --git a/test/box-tap/gh-4231-box-execute-locking.test.lua b/test/box-tap/gh-4231-box-execute-locking.test.lua
index 52c60f764..f3df2eb0f 100755
--- a/test/box-tap/gh-4231-box-execute-locking.test.lua
+++ b/test/box-tap/gh-4231-box-execute-locking.test.lua
@@ -4,20 +4,43 @@
-- before box will be loaded) in several fibers in parallel and
-- ensure that it returns correct results (i.e. that the function
-- waits until box will be fully configured).
+--
+-- The test can be configured to call box.execute() from a fiber
+-- instead of box_load_and_execute(): it can be done either via
+-- test-run using confguration feature or using an argument when
+-- the test is invoked directly.
local fiber = require('fiber')
local tap = require('tap')
+-- Determine configuration.
+local conf = 'box_load_and_execute'
+local ok, test_run = pcall(require, 'test_run')
+if ok then
+ test_run = test_run.new()
+ conf = test_run:get_cfg('conf')
+elseif #arg >= 1 then
+ conf = arg[1]
+end
+assert(conf == 'box_load_and_execute' or
+ conf == 'box.execute')
+
local box_load_and_execute = box.execute
local fiber_count = 10
local results = fiber.channel(fiber_count)
local function select_from_vindex()
- local res = box_load_and_execute('SELECT * FROM "_vindex"')
+ local box_execute_func =
+ conf == 'box_load_and_execute' and box_load_and_execute or
+ conf == 'box.execute' and box.execute or
+ function() return false end
+
+ local res = box_execute_func('SELECT * FROM "_vindex"')
results:put(res)
end
local test = tap.test('gh-4231-box-execute-locking')
+test:diag('configuration: %s', conf)
test:plan(fiber_count)
diff --git a/test/box-tap/suite.cfg b/test/box-tap/suite.cfg
new file mode 100644
index 000000000..91a721d47
--- /dev/null
+++ b/test/box-tap/suite.cfg
@@ -0,0 +1,6 @@
+{
+ "gh-4231-box-execute-locking.test.lua": {
+ "box_load_and_execute": {"conf": "box_load_and_execute"},
+ "box.execute": {"conf": "box.execute"}
+ }
+}
diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini
index 8d9e32d3f..5b764593a 100644
--- a/test/box-tap/suite.ini
+++ b/test/box-tap/suite.ini
@@ -5,3 +5,4 @@ is_parallel = True
pretest_clean = True
fragile = cfg.test.lua ; gh-4344
key_def.test.lua ; gh-4252
+config = suite.cfg
--
2.25.0
More information about the Tarantool-patches
mailing list