Skip to content

Commit 48e6e9d

Browse files
SerpentianGerold103
authored andcommitted
storage: fix core_version string in exports
exports_deploy_funcs() used to log the core version as nil. The problem is the fact, that table.concat was used for core version string, so the complied exports always had nil instead of core_version. table.concat doesn't work with non-array tables, as they have no defined order. Let's explicitly define __tostring function for version and use it in order to log core version. Closes #465 NO_DOC=bugfix
1 parent ac8f82b commit 48e6e9d

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

test/unit-luatest/storage_exports_test.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,15 @@ test_group.test_deploy_privs = function(g)
135135
box.schema.role.drop('two')
136136
end)
137137
end
138+
139+
test_group.test_core_version = function(g)
140+
g.server:exec(function()
141+
local exports = _G.ivexports.log[#_G.ivexports.log]
142+
exports = _G.ivexports.compile(exports)
143+
144+
local version = _TARANTOOL
145+
local pos = version:find('-g')
146+
version = version:sub(1, pos - 1)
147+
ilt.assert_equals(exports.core_version, version)
148+
end)
149+
end

test/unit-luatest/version_test.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ local lversion = require('vshard.version')
33

44
local g = t.group('version')
55

6+
local function assert_version_str_equals(actual, expected)
7+
-- Remove commit hash, if it exists. It's not saved in version.
8+
local hash_pos = expected:find('-g')
9+
if hash_pos then
10+
expected = expected:sub(1, hash_pos - 1)
11+
end
12+
-- Remove trailing dash.
13+
if expected:sub(-1) == '-' then
14+
expected = expected:sub(1, -2)
15+
end
16+
-- Add 0 number of commits to expected.
17+
if actual:sub(-2) == '-0' and not expected:find('-0') then
18+
expected = expected .. '-0'
19+
end
20+
t.assert_equals(actual, expected)
21+
end
22+
623
g.test_order = function()
724
-- Example of a full version: 2.10.0-beta2-86-gc9981a567.
825
local versions = {
@@ -215,6 +232,7 @@ g.test_order = function()
215232
t.assert(not (ver > v.ver), ('versions not >, %d'):format(i))
216233
t.assert(ver <= v.ver, ('versions <=, %d'):format(i))
217234
t.assert(ver >= v.ver, ('versions <=, %d'):format(i))
235+
assert_version_str_equals(tostring(ver), v.str)
218236
if i > 1 then
219237
local prev = versions[i - 1].ver
220238
t.assert(prev < ver, ('versions <, %d'):format(i))

vshard/storage/exports.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ local function exports_compile(exports)
4343
end
4444
return {
4545
vshard_version = exports.version,
46-
core_version = table.concat(lvutil.core_version, '.'),
46+
core_version = tostring(lvutil.core_version),
4747
funcs = compiled_funcs,
4848
}
4949
end

vshard/version.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ local version_mt = {
7575
__le = function(l, r)
7676
return version_cmp(l, r) <= 0
7777
end,
78+
__tostring = function(v)
79+
local str = v.id_major .. '.' .. v.id_middle .. '.' .. v.id_minor
80+
if v.rel_type then
81+
str = str .. '-' .. v.rel_type
82+
if v.rel_num ~= 0 then
83+
str = str .. v.rel_num
84+
end
85+
end
86+
str = str .. '-' .. v.id_commit
87+
return str
88+
end,
7889
}
7990

8091
local function version_new(id_major, id_middle, id_minor, rel_type, rel_num,

0 commit comments

Comments
 (0)