Skip to content

Commit 1ed52a2

Browse files
Oleg Chaplashkinylobankov
authored andcommitted
Add server wrappers for the box.cfg interaction
Now server module contains two new wrappers for the interacting with the `box.cfg` variable on the remote server instance. Server:update_box_cfg(cfg) - performs a simple call to `box.cfg(cfg)` on server instance. `cfg` type must be a table. If type is incorrect, then the following error will be raised: `bad argument to update_box_cfg (table expected, got <your_bad_type>)` Server:get_box_cfg() - performs a simple call to `return box.cfg` on server instance. This function doesn't take any parameters. Usage example: ``` server:update_box_cfg{read_only = true} local cfg = server:get_box_cfg() print(cfg.read_only) -- will be printed `true` ``` Closes #232
1 parent 9e117e6 commit 1ed52a2

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
- `Server:wait_for_vclock()`
3535
- `Server:wait_for_downstream_to()`
3636
- `Server:wait_for_vclock_of()`
37+
- `Server:update_box_cfg()`
38+
- `Server:get_box_cfg()`
3739
- Check docs generation with LDoc.
3840
- Add `--repeat-group` (`-R`) option to run tests in a circle within the group.
3941
- Forbid negative values for `--repeat` (`-r`) option.

luatest/server.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,23 @@ function Server:wait_for_vclock_of(other_server)
841841
self:wait_for_vclock(vclock)
842842
end
843843

844+
-- Box configuration
845+
846+
--- A simple wrapper around the `Server:exec()` method
847+
-- to update the `box.cfg` value on the server.
848+
--
849+
-- @tab cfg Box configuration settings.
850+
function Server:update_box_cfg(cfg)
851+
checks('?', 'table')
852+
return self:exec(function(c) box.cfg(c) end, {cfg})
853+
end
854+
855+
--- A simple wrapper around the `Server:exec()` method
856+
-- to get the `box.cfg` value from the server.
857+
--
858+
-- @return table
859+
function Server:get_box_cfg()
860+
return self:exec(function() return box.cfg end)
861+
end
862+
844863
return Server

test/boxcfg_interaction_test.lua

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
local fio = require('fio')
2+
local t = require('luatest')
3+
4+
local g = t.group()
5+
local Server = t.Server
6+
7+
local root = fio.dirname(fio.dirname(fio.abspath(package.search('test.helper'))))
8+
local datadir = fio.pathjoin(root, 'tmp', 'boxcfg_interaction')
9+
local command = fio.pathjoin(root, 'test', 'server_instance.lua')
10+
11+
g.before_all(function()
12+
fio.rmtree(datadir)
13+
14+
local workdir = fio.tempdir()
15+
local log = fio.pathjoin(workdir, 'boxcfg_interaction.log')
16+
17+
g.server = Server:new({
18+
command = command,
19+
workdir = fio.pathjoin(datadir, 'boxcfg_interaction'),
20+
env = {
21+
TARANTOOL_LOG = log
22+
},
23+
box_cfg = {read_only = false},
24+
http_port = 8187,
25+
net_box_port = 3138,
26+
})
27+
fio.mktree(g.server.workdir)
28+
29+
g.server:start()
30+
t.helpers.retrying({timeout = 2}, function()
31+
g.server:http_request('get', '/ping')
32+
end)
33+
34+
g.server:connect_net_box()
35+
end)
36+
37+
g.after_all(function()
38+
g.server:drop()
39+
fio.rmtree(datadir)
40+
end)
41+
42+
g.test_update_box_cfg = function()
43+
g.server:update_box_cfg{read_only = true}
44+
45+
local c = g.server:exec(function() return box.cfg end)
46+
47+
t.assert_type(c, 'table')
48+
t.assert_equals(c.read_only, true)
49+
t.assert(
50+
g.server:grep_log(
51+
"I> set 'read_only' configuration option to true"
52+
)
53+
)
54+
end
55+
56+
g.test_update_box_cfg_multiple_parameters = function()
57+
g.server:update_box_cfg{checkpoint_count = 5, replication_timeout = 2}
58+
59+
local c = g.server:exec(function() return box.cfg end)
60+
61+
t.assert_type(c, 'table')
62+
63+
t.assert_equals(c.checkpoint_count, 5)
64+
t.assert(
65+
g.server:grep_log(
66+
"I> set 'checkpoint_count' configuration option to 5"
67+
)
68+
)
69+
70+
t.assert_equals(c.replication_timeout, 2)
71+
t.assert(
72+
g.server:grep_log(
73+
"I> set 'replication_timeout' configuration option to 2"
74+
)
75+
)
76+
end
77+
78+
g.test_update_box_cfg_bad_type = function()
79+
local function foo()
80+
g.server:update_box_cfg(1)
81+
end
82+
t.assert_error_msg_contains(
83+
'bad argument #2 to update_box_cfg (table expected, got number)', foo)
84+
85+
end
86+
87+
g.test_get_box_cfg = function()
88+
local cfg1 = g.server:get_box_cfg()
89+
local cfg2 = g.server:exec(function() return box.cfg end)
90+
91+
t.assert_equals(cfg1, cfg2)
92+
end

test/server_instance.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ local json = require('json')
55
local workdir = os.getenv('TARANTOOL_WORKDIR')
66
local listen = os.getenv('TARANTOOL_LISTEN')
77
local http_port = os.getenv('TARANTOOL_HTTP_PORT')
8+
local log = os.getenv('TARANTOOL_LOG')
89

910
local httpd = require('http.server').new('0.0.0.0', http_port)
1011

11-
box.cfg({work_dir = workdir})
12+
box.cfg({work_dir = workdir, log = log})
1213
box.schema.user.grant('guest', 'super', nil, nil, {if_not_exists = true})
1314
box.cfg({listen = listen})
1415

0 commit comments

Comments
 (0)