Skip to content

Commit f37b353

Browse files
ImeevMATotktonada
authored andcommitted
Accept table as new_box_uri
Prior to this patch, box.cfg.listen was only set to string or number, although table is also supported by require('uri').parse(). Because of this, it was not possible to use the table as net_box_uri when creating the server. This patch allows the table to be used as net_box_uri. Note, that for backward compatiblity net_box_uri given as table is converted to string before setting as box.cfg.listen. This is done because most of server implementations support box.cfg.listen as string. Closes #342
1 parent a8b0389 commit f37b353

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
* Fixed incorrent unix socket path length check (gh-341).
6+
* Now net_box_uri can be accepted as table (gh-342).
67

78
## 1.0.0
89

luatest/server.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ local Server = {
4141

4242
http_port = '?number',
4343
net_box_port = '?number',
44-
net_box_uri = '?string',
44+
net_box_uri = '?string|table',
4545
net_box_credentials = '?table',
4646

4747
alias = '?string',
@@ -167,6 +167,9 @@ function Server:initialize()
167167
:format(max_unix_socket_path[system]))
168168
end
169169
end
170+
if type(self.net_box_uri) == 'table' then
171+
self.net_box_uri = uri.format(parsed_net_box_uri, true)
172+
end
170173

171174
self.env = utils.merge(self.env or {}, self:build_env())
172175
self.args = self.args or {}
@@ -358,7 +361,7 @@ function Server:restart(params, opts)
358361

359362
http_port = '?number',
360363
net_box_port = '?number',
361-
net_box_uri = '?string',
364+
net_box_uri = '?string|table',
362365
net_box_credentials = '?table',
363366

364367
alias = '?string',

test/server_test.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local fio = require('fio')
22
local json = require('json')
3+
local urilib = require('uri')
34

45
local t = require('luatest')
56
local g = t.group()
@@ -321,6 +322,54 @@ g.test_unix_socket_not_include_uri_fields = function()
321322
s:stop()
322323
end
323324

325+
g.test_table_uri_success = function()
326+
t.skip_if(not utils.version_current_ge_than(2, 10, 0),
327+
"URI as a table is supported since Tarantool 2.10.0.")
328+
local workdir = fio.pathjoin(datadir, 'unix_socket')
329+
fio.mktree(workdir)
330+
local net_box_uri = {
331+
uri = 'unix/:' .. fio.pathjoin(workdir, '/test_socket.sock'),
332+
params = {
333+
transport = 'plain'
334+
},
335+
}
336+
local res = urilib.format(urilib.parse(net_box_uri))
337+
local s = Server:new({
338+
command = command,
339+
workdir = workdir,
340+
net_box_uri = net_box_uri,
341+
http_port = 0, -- unused
342+
})
343+
s:start()
344+
t.helpers.retrying({}, function() s:connect_net_box() end)
345+
t.assert_equals(s:exec(function() return box.cfg.listen end), res)
346+
s:stop()
347+
end
348+
349+
g.test_table_uri_error = function()
350+
t.skip_if(utils.version_current_ge_than(2, 10, 0),
351+
"URI as a table is supported since Tarantool 2.10.0.")
352+
local workdir = fio.pathjoin(datadir, 'unix_socket')
353+
fio.mktree(workdir)
354+
local net_box_uri = {
355+
login = 'guest',
356+
uri = 'unix/:' .. fio.pathjoin(workdir, '/test_socket.sock'),
357+
params = {
358+
transport = 'plain'
359+
},
360+
}
361+
local err = [[bad argument #2 to 'uri_parse' (cannot convert 'table' ]] ..
362+
[[to 'const char *')]]
363+
t.assert_error_msg_contains(
364+
err, Server.new, Server, {
365+
command = command,
366+
workdir = workdir,
367+
net_box_uri = net_box_uri,
368+
http_port = 0, -- unused
369+
}
370+
)
371+
end
372+
324373
g.test_server_start_with_coverage_enabled = function()
325374
t.skip_if(server.coverage_report, 'Coverage is already enabled. Nothing to test')
326375
server:restart({coverage_report = true})

0 commit comments

Comments
 (0)