Skip to content

Commit e3b6244

Browse files
ligurioTotktonada
authored andcommitted
test: add integration tests
test-run supports three types of tests [1]: - tarantool - Test-Suite for Functional Testing - app - Another functional Test-Suite - unittest - Unit-Testing Test Suite Patch adds tests for all three test types: - test/test-app for type 'app' - test/test-tarantool for type 'tarantool' - test/test-unit for type 'unittest' How-to run: $ make test_integration 1. https://github.com/tarantool/test-run#test-suite
1 parent 5941741 commit e3b6244

20 files changed

+368
-2
lines changed

.luacheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ include_files = {
2626

2727
exclude_files = {
2828
"lib/tarantool-python",
29+
"test/test-tarantool/*.test.lua",
2930
}

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
TEST_RUN_EXTRA_PARAMS?=
2+
PYTHON?=python
3+
14
default:
25
false
36

4-
.PHONY: lint flake8 luacheck
57
lint: flake8 luacheck
68

79
flake8:
8-
python -m flake8 *.py lib/*.py
10+
$(PYTHON) -m flake8 *.py lib/*.py
911

1012
luacheck:
1113
luacheck --config .luacheckrc .
14+
15+
test_integration:
16+
$(PYTHON) test/test-run.py --force $(TEST_RUN_EXTRA_PARAMS)
17+
18+
test: test_integration
19+
20+
.PHONY: lint flake8 luacheck test test_integration

test/test-app/cfg.test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env tarantool
2+
3+
-- Test is an example of TAP test
4+
5+
local tap = require('tap')
6+
local test = tap.test('cfg')
7+
test:plan(4)
8+
9+
box.cfg{listen = box.NULL}
10+
test:is(nil, box.info.listen, 'no cfg.listen - no info.listen')
11+
12+
box.cfg{listen = '127.0.0.1:0'}
13+
test:ok(box.info.listen:match('127.0.0.1'), 'real IP in info.listen')
14+
test:ok(not box.info.listen:match(':0'), 'real port in info.listen')
15+
16+
box.cfg{listen = box.NULL}
17+
test:is(nil, box.info.listen, 'cfg.listen reset drops info.listen')
18+
19+
os.exit(test:check() and 0 or 1)

test/test-app/suite.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
core = app
3+
description = application tests
4+
is_parallel = True
5+
pretest_clean = True
6+
use_unix_sockets_iproto = True

test/test-run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test-run.py

test/test-tarantool/box.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env tarantool
2+
local os = require('os')
3+
4+
box.cfg{
5+
listen = os.getenv("LISTEN"),
6+
memtx_memory = 107374182,
7+
pid_file = "tarantool.pid",
8+
force_recovery = true,
9+
wal_max_size = 500
10+
}
11+
12+
require('console').listen(os.getenv('ADMIN'))

test/test-tarantool/engine.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"set_language.test.sql": {
3+
"memtx": {"engine": "memtx"}
4+
},
5+
"setopt_delimeter.test.lua": {
6+
"memtx": {"engine": "memtx"}
7+
},
8+
"worker_hang_when_gc_triggered_inside_colorer.test.lua": {
9+
"vinyl": {"engine": "vinyl"}
10+
},
11+
"*": {
12+
"memtx": {"engine": "memtx"},
13+
"vinyl": {"engine": "vinyl"}
14+
}
15+
}

test/test-tarantool/iproto.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
IPROTO_UPDATE
2+
query [('IPROTO_CODE', 4)] [('IPROTO_SPACE_ID', 280)]
3+
True
4+
query [('IPROTO_CODE', 4)] [('IPROTO_KEY', (1,)), ('IPROTO_SPACE_ID', 280)]
5+
True
6+
7+

test/test-tarantool/iproto.test.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Original Tarantool's test box-py/iproto.test.py had a problem when output with
3+
running under Python 2 was not the same as with running under Python 3.
4+
5+
Fixed in commit 697b79781cc63e2d87d86d43713998261d602334
6+
"test: make output of box-py/iproto.test.py deterministic".
7+
"""
8+
9+
from __future__ import print_function
10+
11+
import msgpack
12+
from tarantool.const import *
13+
from tarantool import Connection
14+
from tarantool.response import Response
15+
from lib.tarantool_connection import TarantoolConnection
16+
17+
# Note re IPROTO_SQL_INFO_* keys: they cannot appear in the
18+
# response map at the top level, but have the same codes as other
19+
# IPROTO_* constants. Exclude those names so.
20+
key_names = {}
21+
for (k,v) in list(globals().items()):
22+
if type(k) == str and k.startswith("IPROTO_") and \
23+
not k.startswith("IPROTO_SQL_INFO_") and type(v) == int:
24+
key_names[v] = k
25+
26+
def repr_dict(todump):
27+
d = {}
28+
for (k, v) in todump.items():
29+
k_name = key_names.get(k, k)
30+
d[k_name] = v
31+
return repr(sorted(d.items()))
32+
33+
34+
def test(header, body):
35+
# Connect and authenticate
36+
c = Connection("localhost", server.iproto.port)
37+
c.connect()
38+
print("query", repr_dict(header), repr_dict(body))
39+
header = msgpack.dumps(header)
40+
body = msgpack.dumps(body)
41+
query = msgpack.dumps(len(header) + len(body)) + header + body
42+
# Send raw request using connected socket
43+
s = c._socket
44+
try:
45+
s.send(query)
46+
except OSError as e:
47+
print(" => ", "Failed to send request")
48+
c.close()
49+
print(iproto.py_con.ping() > 0)
50+
51+
print("IPROTO_UPDATE")
52+
test({ IPROTO_CODE : REQUEST_TYPE_UPDATE }, { IPROTO_SPACE_ID: 280 })
53+
test({ IPROTO_CODE : REQUEST_TYPE_UPDATE },
54+
{ IPROTO_SPACE_ID: 280, IPROTO_KEY: (1, )})
55+
print("\n")

test/test-tarantool/replica.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env tarantool
2+
3+
local repl_include_self = arg[1] and arg[1] == 'true' or false
4+
local repl_list
5+
6+
if repl_include_self then
7+
repl_list = {os.getenv("MASTER"), os.getenv("LISTEN")}
8+
else
9+
repl_list = os.getenv("MASTER")
10+
end
11+
12+
-- Start the console first to allow test-run to attach even before
13+
-- box.cfg is finished.
14+
require('console').listen(os.getenv('ADMIN'))
15+
16+
box.cfg({
17+
listen = os.getenv("LISTEN"),
18+
replication = repl_list,
19+
memtx_memory = 107374182,
20+
replication_timeout = 0.1,
21+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- test-run result file version 2
2+
-- Simple SQL test that uses '\set language' command.
3+
-- Command introduced in commit 6e38b88eb6bbe543a1e3ba0a6a0be2f6f58abc86
4+
-- ('Implement SQL driver')
5+
6+
-- Create table for tests
7+
CREATE TABLE t (a BOOLEAN PRIMARY KEY);
8+
| ---
9+
| - row_count: 1
10+
| ...
11+
INSERT INTO t VALUES (true), (false);
12+
| ---
13+
| - row_count: 2
14+
| ...
15+
16+
-- Create user-defined function.
17+
\set language lua
18+
| ---
19+
| - true
20+
| ...
21+
test_run = require('test_run').new()
22+
| ---
23+
| ...
24+
\set language sql
25+
| ---
26+
| - true
27+
| ...
28+
29+
SELECT a FROM t WHERE a;
30+
| ---
31+
| - metadata:
32+
| - name: A
33+
| type: boolean
34+
| rows:
35+
| - [true]
36+
| ...
37+
SELECT a FROM t WHERE a != true;
38+
| ---
39+
| - metadata:
40+
| - name: A
41+
| type: boolean
42+
| rows:
43+
| - [false]
44+
| ...
45+
46+
-- Cleaning.
47+
DROP TABLE t;
48+
| ---
49+
| - row_count: 1
50+
| ...
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Simple SQL test that uses '\set language' command.
2+
-- Command introduced in commit 6e38b88eb6bbe543a1e3ba0a6a0be2f6f58abc86
3+
-- ('Implement SQL driver')
4+
5+
-- Create table for tests
6+
CREATE TABLE t (a BOOLEAN PRIMARY KEY);
7+
INSERT INTO t VALUES (true), (false);
8+
9+
-- Create user-defined function.
10+
\set language lua
11+
test_run = require('test_run').new()
12+
\set language sql
13+
14+
SELECT a FROM t WHERE a;
15+
SELECT a FROM t WHERE a != true;
16+
17+
-- Cleaning.
18+
DROP TABLE t;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- test-run result file version 2
2+
-- Simple test that uses 'setopt delimiter' command.
3+
-- Command introduced in commit 6e38b88eb6bbe543a1e3ba0a6a0be2f6f58abc86
4+
-- ('Implement SQL driver')
5+
6+
test_run = require('test_run').new()
7+
| ---
8+
| ...
9+
10+
-- Using delimiter
11+
_ = test_run:cmd("setopt delimiter ';'")
12+
| ---
13+
| ...
14+
function test_a()
15+
local a = 1
16+
end;
17+
| ---
18+
| ...
19+
_ = test_run:cmd("setopt delimiter ''");
20+
| ---
21+
| ...
22+
23+
box.cfg{}
24+
| ---
25+
| ...
26+
27+
-- Using multiline
28+
box.cfg{ \
29+
coredump = false, \
30+
log_format = 'plain', \
31+
log_level = 5, \
32+
strip_core = true \
33+
}
34+
| ---
35+
| ...
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Simple test that uses 'setopt delimiter' command.
2+
-- Command introduced in commit 6e38b88eb6bbe543a1e3ba0a6a0be2f6f58abc86
3+
-- ('Implement SQL driver')
4+
5+
test_run = require('test_run').new()
6+
7+
-- Using delimiter
8+
_ = test_run:cmd("setopt delimiter ';'")
9+
function test_a()
10+
local a = 1
11+
end;
12+
_ = test_run:cmd("setopt delimiter ''");
13+
14+
box.cfg{}
15+
16+
-- Using multiline
17+
box.cfg{ \
18+
coredump = false, \
19+
log_format = 'plain', \
20+
log_level = 5, \
21+
strip_core = true \
22+
}

test/test-tarantool/suite.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[default]
2+
core = tarantool
3+
description = tarantool tests
4+
script = box.lua
5+
use_unix_sockets = True
6+
pretest_clean = True
7+
config = engine.cfg
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- test-run result file version 2
2+
-- regression test for the problem fixed in [1] that was a part
3+
-- of more common issue [2]. It's worth to mention that original
4+
-- problem has more chances to reproduce with applied patch to
5+
-- multiprocessing source code (multiprocessing/connection.py).
6+
--
7+
-- 1. https://github.com/tarantool/test-run/pull/275
8+
-- 2. https://github.com/tarantool/tarantool-qa/issues/96
9+
10+
-- Setup
11+
box.schema.user.grant('guest', 'replication')
12+
| ---
13+
| ...
14+
15+
-- Setup and teardown cluster, manage separate instances.
16+
test_run = require('test_run').new()
17+
| ---
18+
| ...
19+
test_run:cmd('create server replica with rpl_master=default, script="test-tarantool/replica.lua"')
20+
| ---
21+
| - true
22+
| ...
23+
test_run:cmd('start server replica')
24+
| ---
25+
| - true
26+
| ...
27+
test_run:cmd('stop server replica')
28+
| ---
29+
| - true
30+
| ...
31+
test_run:cmd('cleanup server replica')
32+
| ---
33+
| - true
34+
| ...
35+
test_run:cmd('delete server replica')
36+
| ---
37+
| - true
38+
| ...
39+
40+
-- Teardown
41+
box.schema.user.revoke('guest', 'replication')
42+
| ---
43+
| ...
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- regression test for the problem fixed in [1] that was a part
2+
-- of more common issue [2]. It's worth to mention that original
3+
-- problem has more chances to reproduce with applied patch to
4+
-- multiprocessing source code (multiprocessing/connection.py).
5+
--
6+
-- 1. https://github.com/tarantool/test-run/pull/275
7+
-- 2. https://github.com/tarantool/tarantool-qa/issues/96
8+
9+
-- Setup
10+
box.schema.user.grant('guest', 'replication')
11+
12+
-- Setup and teardown cluster, manage separate instances.
13+
test_run = require('test_run').new()
14+
test_run:cmd('create server replica with rpl_master=default, script="test-tarantool/replica.lua"')
15+
test_run:cmd('start server replica')
16+
test_run:cmd('stop server replica')
17+
test_run:cmd('cleanup server replica')
18+
test_run:cmd('delete server replica')
19+
20+
-- Teardown
21+
box.schema.user.revoke('guest', 'replication')

test/test-unit/broken_unicode.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TAP version 13
2+
1..3
3+
ok 1 - ��
4+
ok 2 - ��
5+
ok 3 - ☠

test/test-unit/broken_unicode.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# Test is needed to check how test-run handle
4+
# tests with result files. Since commit
5+
# 395edeb6b743c4479a62dd2183062124973d2b2a
6+
# 'python3: decouple bytes and strings' test-run
7+
# reads test output and result files in byte mode.
8+
# Output of this test contains broken UTF-8 sequences
9+
# and test-run will fail if it will try to decode output.
10+
11+
printf 'TAP version 13\n'
12+
printf '1..3\n'
13+
printf 'ok 1 - \302\302\n'
14+
printf 'ok 2 - \302\302\n'
15+
printf 'ok 3 - \342\230\240\n'

0 commit comments

Comments
 (0)