-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, also added some comments and removed duplicate code
- Loading branch information
Showing
5 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
require('strict').on() | ||
|
||
local log = require('log') | ||
local errors = require('errors') | ||
local cartridge = require('cartridge') | ||
errors.set_deprecation_handler(function(err) | ||
log.error('%s', err) | ||
os.exit(1) | ||
end) | ||
|
||
package.preload['mymodule'] = function() | ||
|
||
return { | ||
role_name = 'myrole', | ||
validate_config = function() | ||
return true | ||
end, | ||
init = function(opts) end, | ||
apply_config = function(_, opts) end, | ||
stop = function() end, | ||
} | ||
end | ||
|
||
local ok, err = errors.pcall('CartridgeCfgError', cartridge.cfg, { | ||
advertise_uri = 'localhost:3301', | ||
http_port = 8081, | ||
bucket_count = 3000, | ||
roles = { | ||
'mymodule', | ||
}, | ||
roles_reload_allowed = true, | ||
-- Compatibility tests run on cartridge 1.2.0 | ||
-- which doesn't support it yet. | ||
upload_prefix = package.loaded['cartridge.upload'] and '../upload', | ||
}) | ||
if not ok then | ||
log.error('%s', err) | ||
os.exit(1) | ||
end | ||
|
||
_G.is_initialized = cartridge.is_healthy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require('strict').on() | ||
|
||
local fio = require('fio') | ||
local digest = require('digest') | ||
local helpers = table.copy(require('cartridge.test-helpers')) | ||
|
||
helpers.project_root = fio.dirname(debug.sourcedir()) | ||
|
||
fio.tempdir = function(base) | ||
base = base or os.getenv('TMPDIR') or '/tmp' | ||
local random = digest.urandom(9) | ||
local suffix = digest.base64_encode(random, {urlsafe = true}) | ||
local path = fio.pathjoin(base, 'tmp.cartridge.' .. suffix) | ||
fio.mktree(path) | ||
return path | ||
end | ||
|
||
function helpers.entrypoint(name) | ||
local path = fio.pathjoin( | ||
helpers.project_root, | ||
'test', 'entrypoint', | ||
string.format('%s.lua', name) | ||
) | ||
if not fio.path.exists(path) then | ||
error(path .. ': no such entrypoint', 2) | ||
end | ||
return path | ||
end | ||
|
||
return helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
local fio = require('fio') | ||
local utils = require('cartridge.utils') | ||
local t = require('luatest') | ||
local g = t.group("hot_reload") | ||
|
||
local helpers = require('test.helper') | ||
|
||
local function reload_myrole(fn) | ||
-- For the sake of string.dump() function must have no upvalues. | ||
-- https://www.lua.org/manual/5.1/manual.html#pdf-string.dump | ||
utils.assert_upvalues(fn, {}) | ||
|
||
local ok, err = g.srv.net_box:eval([[ | ||
package.preload["mymodule"] = loadstring(...) | ||
return require("cartridge.roles").reload() | ||
]], {string.dump(fn)}) | ||
|
||
t.assert_equals({ok, err}, {true, nil}) | ||
end | ||
|
||
g.before_all(function() | ||
local tempdir = fio.tempdir() | ||
g.cluster = helpers.Cluster:new({ | ||
datadir = tempdir, | ||
server_command = helpers.entrypoint('srv_basic'), | ||
cookie = "secret-cluster-cookie", | ||
replicasets = {{ | ||
alias = 'A', | ||
roles = {'myrole'}, | ||
servers = 1, | ||
}}, | ||
}) | ||
g.srv = g.cluster:server('A-1') | ||
g.cluster:start() | ||
|
||
local ok, err = g.srv.net_box:eval([[ | ||
local a = box.schema.create_space('origin', { | ||
if_not_exists = true | ||
}) | ||
a:create_index('pri') | ||
return true, nil | ||
]]) | ||
t.assert_equals({ok, err}, {true, nil}) | ||
end) | ||
|
||
g.after_all(function() | ||
g.cluster:stop() | ||
fio.rmtree(g.cluster.datadir) | ||
end) | ||
|
||
function g.test_reload_config() | ||
reload_myrole(function() | ||
return { | ||
role_name = 'myrole', | ||
init = function() | ||
rawset(_G, "expirationd", require('expirationd')) | ||
box.space.origin:insert({1}) | ||
local function is_expired(args, tuple) | ||
return true | ||
end | ||
expirationd.start("clean_all", box.space.origin.id, is_expired, {force = true}) | ||
return true, nil | ||
end, | ||
stop = function() | ||
for _, task in pairs(expirationd.tasks()) do | ||
expirationd.kill(task) | ||
end | ||
box.space.origin:insert({2}) | ||
end | ||
} | ||
end) | ||
t.assert_equals( | ||
g.srv.net_box:eval('return box.space.origin:select()'), | ||
{} | ||
) | ||
reload_myrole(function() | ||
return { | ||
role_name = 'myrole', | ||
init = function() | ||
rawset(_G, "expirationd", require('expirationd')) | ||
local function is_expired(args, tuple) | ||
return true | ||
end | ||
expirationd.start("clean_all", box.space.origin.id, is_expired) | ||
return true, nil | ||
end, | ||
stop = function() | ||
for _, task in pairs(expirationd.tasks()) do | ||
expirationd.kill(task) | ||
end | ||
end | ||
} | ||
end) | ||
t.assert_equals( | ||
g.srv.net_box:eval('return box.space.origin:select()'), | ||
{{ 2 }} | ||
) | ||
end |