-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c30dd
commit c4fe272
Showing
16 changed files
with
1,184 additions
and
452 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
local fio = require('fio') | ||
local server = require('luatest.server') | ||
local t = require('luatest') | ||
local treegen = require('test.treegen') | ||
local justrun = require('test.justrun') | ||
local g = t.group() | ||
|
||
g.before_all(function() | ||
treegen.init(g) | ||
end) | ||
|
||
g.after_all(function() | ||
treegen.clean(g) | ||
end) | ||
|
||
g.before_each(function(cg) | ||
cg.server = server:new { | ||
box_cfg = {}, | ||
workdir = fio.cwd() .. '/tmp' | ||
} | ||
cg.server:start() | ||
cg.server:exec(function() | ||
box.schema.space.create('bands') | ||
box.space.bands:format({ | ||
{ name = 'id', type = 'unsigned' }, | ||
{ name = 'band_name', type = 'string' }, | ||
{ name = 'year', type = 'unsigned' } | ||
}) | ||
box.space.bands:create_index('primary', { parts = { 'id' } }) | ||
end) | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.server:stop() | ||
cg.server:drop() | ||
end) | ||
|
||
g.test_config_option = function() | ||
local dir = treegen.prepare_directory(g, {}, {}) | ||
local file_config = [[ | ||
log: | ||
level: 7 | ||
memtx: | ||
min_tuple_size: 32 | ||
memory: 100000000 | ||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
instances: | ||
instance-001: {} | ||
]] | ||
treegen.write_script(dir, 'config.yaml', file_config) | ||
|
||
local script = [[ | ||
print(box.cfg.memtx_min_tuple_size) | ||
print(box.cfg.memtx_memory) | ||
print(box.cfg.log_level) | ||
os.exit(0) | ||
]] | ||
treegen.write_script(dir, 'main.lua', script) | ||
|
||
local env = {TT_LOG_LEVEL = 0} | ||
local opts = {nojson = true, stderr = false} | ||
local args = {'--name', 'instance-001', '--config', 'config.yaml', | ||
'main.lua'} | ||
local res = justrun.tarantool(dir, env, args, opts) | ||
t.assert_equals(res.exit_code, 0) | ||
t.assert_equals(res.stdout, table.concat({32, 100000000, 0}, "\n")) | ||
end |
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,5 @@ | ||
config: | ||
etcd: | ||
prefix: /example | ||
endpoints: | ||
- http://localhost:2379 |
35 changes: 35 additions & 0 deletions
35
doc/code_snippets/test/config/remote_replicaset_manual.yaml
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,35 @@ | ||
credentials: | ||
users: | ||
replicator: | ||
password: 'topsecret' | ||
roles: [replication] | ||
client: | ||
password: 'secret' | ||
roles: [super] | ||
|
||
iproto: | ||
advertise: | ||
peer: replicator@ | ||
|
||
replication: | ||
failover: manual | ||
|
||
app: | ||
module: myapp | ||
cfg: {} | ||
|
||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
leader: instance-002 | ||
instances: | ||
instance-001: | ||
iproto: | ||
listen: 127.0.0.1:3301 | ||
instance-002: | ||
iproto: | ||
listen: 127.0.0.1:3302 | ||
instance-003: | ||
iproto: | ||
listen: 127.0.0.1:3303 |
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 @@ | ||
credentials: | ||
users: | ||
replicator: | ||
password: 'topsecret' | ||
roles: [replication] | ||
client: | ||
password: 'secret' | ||
roles: [super] | ||
|
||
iproto: | ||
advertise: | ||
peer: replicator@ | ||
|
||
replication: | ||
failover: election | ||
|
||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
instances: | ||
instance-001: | ||
iproto: | ||
listen: 127.0.0.1:3301 | ||
instance-002: | ||
iproto: | ||
listen: 127.0.0.1:3302 | ||
instance-003: | ||
iproto: | ||
listen: 127.0.0.1:3303 |
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,31 @@ | ||
credentials: | ||
users: | ||
replicator: | ||
password: 'topsecret' | ||
roles: [replication] | ||
client: | ||
password: 'secret' | ||
roles: [super] | ||
|
||
iproto: | ||
advertise: | ||
peer: replicator@ | ||
|
||
replication: | ||
failover: manual | ||
|
||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
leader: instance-001 | ||
instances: | ||
instance-001: | ||
iproto: | ||
listen: 127.0.0.1:3301 | ||
instance-002: | ||
iproto: | ||
listen: 127.0.0.1:3302 | ||
instance-003: | ||
iproto: | ||
listen: 127.0.0.1:3303 |
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,14 @@ | ||
credentials: | ||
users: | ||
guest: | ||
roles: [super] | ||
|
||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
instances: | ||
instance-001: | ||
iproto: | ||
listen: | ||
127.0.0.1:3301 |
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,15 @@ | ||
credentials: | ||
users: | ||
guest: | ||
roles: [super] | ||
|
||
iproto: | ||
listen: | ||
127.0.0.1:3301 | ||
|
||
groups: | ||
group-001: | ||
replicasets: | ||
replicaset-001: | ||
instances: | ||
instance-001: {} |
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,144 @@ | ||
local fun = require('fun') | ||
local log = require('log') | ||
local json = require('json') | ||
local fiber = require('fiber') | ||
local popen = require('popen') | ||
|
||
local justrun = {} | ||
|
||
local function collect_stderr(ph) | ||
local f = fiber.new(function() | ||
local fiber_name = "child's stderr collector" | ||
fiber.name(fiber_name, {truncate = true}) | ||
|
||
local chunks = {} | ||
|
||
while true do | ||
local chunk, err = ph:read({stderr = true}) | ||
if chunk == nil then | ||
log.warn(('%s: got error, exiting: %s'):format( | ||
fiber_name, tostring(err))) | ||
break | ||
end | ||
if chunk == '' then | ||
log.info(('%s: got EOF, exiting'):format(fiber_name)) | ||
break | ||
end | ||
table.insert(chunks, chunk) | ||
end | ||
|
||
-- Glue all chunks, strip trailing newline. | ||
return table.concat(chunks):rstrip() | ||
end) | ||
f:set_joinable(true) | ||
return f | ||
end | ||
|
||
local function cancel_stderr_fiber(stderr_fiber) | ||
if stderr_fiber == nil then | ||
return | ||
end | ||
stderr_fiber:cancel() | ||
end | ||
|
||
local function join_stderr_fiber(stderr_fiber) | ||
if stderr_fiber == nil then | ||
return | ||
end | ||
return select(2, assert(stderr_fiber:join())) | ||
end | ||
|
||
-- Run tarantool in given directory with given environment and | ||
-- command line arguments and catch its output. | ||
-- | ||
-- Expects JSON lines as the output and parses it into an array | ||
-- (it can be disabled using `nojson` option). | ||
-- | ||
-- Options: | ||
-- | ||
-- - nojson (boolean, default: false) | ||
-- | ||
-- Don't attempt to decode stdout as a stream of JSON lines, | ||
-- return as is. | ||
-- | ||
-- - stderr (boolean, default: false) | ||
-- | ||
-- Collect stderr and place it into the `stderr` field of the | ||
-- return value | ||
function justrun.tarantool(dir, env, args, opts) | ||
assert(type(dir) == 'string') | ||
assert(type(env) == 'table') | ||
assert(type(args) == 'table') | ||
local opts = opts or {} | ||
assert(type(opts) == 'table') | ||
|
||
-- Prevent system/user inputrc configuration file from | ||
-- influencing testing code. | ||
env['INPUTRC'] = '/dev/null' | ||
|
||
local tarantool_exe = arg[-1] | ||
-- Use popen.shell() instead of popen.new() due to lack of | ||
-- cwd option in popen (gh-5633). | ||
local env_str = table.concat(fun.iter(env):map(function(k, v) | ||
return ('%s=%q'):format(k, v) | ||
end):totable(), ' ') | ||
local command = ('cd %s && %s %s %s'):format(dir, env_str, tarantool_exe, | ||
table.concat(args, ' ')) | ||
log.info(('Running a command: %s'):format(command)) | ||
local mode = opts.stderr and 'rR' or 'r' | ||
local ph = popen.shell(command, mode) | ||
|
||
local stderr_fiber | ||
if opts.stderr then | ||
stderr_fiber = collect_stderr(ph) | ||
end | ||
|
||
-- Read everything until EOF. | ||
local chunks = {} | ||
while true do | ||
local chunk, err = ph:read() | ||
if chunk == nil then | ||
cancel_stderr_fiber(stderr_fiber) | ||
ph:close() | ||
error(err) | ||
end | ||
if chunk == '' then -- EOF | ||
break | ||
end | ||
table.insert(chunks, chunk) | ||
end | ||
|
||
local exit_code = ph:wait().exit_code | ||
local stderr = join_stderr_fiber(stderr_fiber) | ||
ph:close() | ||
|
||
-- If an error occurs, discard the output and return only the | ||
-- exit code. However, return stderr. | ||
if exit_code ~= 0 then | ||
return { | ||
exit_code = exit_code, | ||
stderr = stderr, | ||
} | ||
end | ||
|
||
-- Glue all chunks, strip trailing newline. | ||
local res = table.concat(chunks):rstrip() | ||
log.info(('Command output:\n%s'):format(res)) | ||
|
||
-- Decode JSON object per line into array of tables (if | ||
-- `nojson` option is not passed). | ||
local decoded | ||
if opts.nojson then | ||
decoded = res | ||
else | ||
decoded = fun.iter(res:split('\n')):map(json.decode):totable() | ||
end | ||
|
||
return { | ||
exit_code = exit_code, | ||
stdout = decoded, | ||
stderr = stderr, | ||
} | ||
end | ||
|
||
return justrun |
Oops, something went wrong.