Skip to content

Commit 3d72b30

Browse files
committed
Update and refine the readme
1 parent 5eadc16 commit 3d72b30

File tree

1 file changed

+194
-58
lines changed

1 file changed

+194
-58
lines changed

README.md

+194-58
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,185 @@
22

33
[![Coverage Status](https://coveralls.io/repos/github/tarantool/test-run/badge.svg)](https://coveralls.io/github/tarantool/test-run)
44

5-
### Test Suite
6-
7-
Bunch of tests, that lay down in the subfolder (recursively) with `suite.ini`
8-
file. `suite.ini` is basic ini-file, that consists of one section `default`,
9-
and a number of fields:
10-
11-
* `core`
12-
* `description` - Test Suite description
13-
* `script` - shebang file to start tarantool with
14-
* disables:
15-
* `disabled` - tests that must be skipped
16-
* `release_disabled` - tests that must be skipped when Tarantool has been
17-
builded with `Release`
18-
* `valgrind_disabled` - tests that must be skipped when Valgrind is enabled
19-
* `lua_libs` - paths for lua files, that should be copied into the folder,
20-
where server is started (delimited with the space, e.g. `lua_libs=lua/1.lua
21-
lua/2.lua`)
22-
* `long_run` - mark tests as long, enabled only with `--long` option (delimited
23-
with the space, e.g. `long_run=t1.test.lua t2.test.lua`)
24-
* `config` - test configuration file name
25-
26-
Field `core` must be one of:
27-
28-
* `tarantool` - Test-Suite for Functional Testing
29-
* `app` - Another functional Test-Suite
30-
* `unittest` - Unit-Testing Test Suite
31-
32-
### Test
33-
34-
Each test consists of files `*.test(.lua|.sql|.py)?`, `*.result`, and may have
35-
skip condition file `*.skipcond`. On first run (without `.result`) `.result`
36-
is generated from output. Each run, in the beggining, `.skipcond` file is
37-
executed. In the local env there's object `self`, that's `Test` object. If test
38-
must be skipped - you must put `self.skip = 1` in this file. Next,
39-
`.test(.lua|.py)?` is executed and file `.reject` is created, then `.reject` is
40-
compared with `.result`. If something differs, then 15 last string of this diff
41-
file are printed and `.reject` file is saving in the `<vardir>/rejects/<suite>`
42-
subfolder given in options or set localy as `var/rejects/<suite>` by default.
43-
If not, then `.reject` file is deleted.
44-
45-
### Test configuration
46-
47-
Test configuration file contains config for multiple run. For each test section
48-
system runs separated test and compares result with common `.result` file. For
49-
example we need to run one test for different db engines("*" means default
5+
6+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
7+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8+
## Table of Contents
9+
10+
- [Test suite configuration file](#test-suite-configuration-file)
11+
- [General configuration values](#general-configuration-values)
12+
- [Disabling and skipping tests](#disabling-and-skipping-tests)
13+
- [Other parameters](#other-parameters)
14+
- [Fragile tests](#fragile-tests)
15+
- [Test composition](#test-composition)
16+
- [Test execution](#test-execution)
17+
- [Test configuration](#test-configuration)
18+
- [Writing various types of tests](#writing-various-types-of-tests)
19+
- [Python tests](#python-tests)
20+
- [Lua](#lua)
21+
- [SQL](#sql)
22+
- [Interaction with the test environment](#interaction-with-the-test-environment)
23+
- [pretest_clean()](#pretest_clean)
24+
- [Tags](#tags)
25+
- [Projects that use test-run](#projects-that-use-test-run)
26+
27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
28+
29+
## Test suite configuration file
30+
31+
Test suite is a bunch of tests located in a directory with a `suite.ini`
32+
file. The `suite.ini` is a basic ini-file with one section `[default]`.
33+
34+
```ini
35+
[default]
36+
core = luatest
37+
description = Example test suite using luatest
38+
...
39+
```
40+
41+
There's a syntax for single- and multiline lists. (TODO see ./sql-tap/suite.ini)
42+
For example:
43+
44+
```ini
45+
single_line = first.test.lua second.test.lua third.test.lua
46+
multiline = first.test.lua ;
47+
second.test.lua ;
48+
third.test.lua ;
49+
...
50+
```
51+
52+
Below is a list of configuration values (fields) in the `suite.ini` file.
53+
54+
### General configuration values
55+
56+
* `core` — major type of tests in this suite.
57+
Should have one of the following values:
58+
59+
* `tarantool` — diff-test, a test that reads a file with commands,
60+
feeds it line by line to the tarantool console,
61+
writes requests and responses to an output file,
62+
and then compares that file with a reference file.
63+
* `app` — a Lua script test.
64+
Most of such tests produce
65+
[TAP13 output](http://testanything.org/tap-version-13-specification.html)
66+
using the built-in `tap` module.
67+
Test-run validates such output without a reference file.
68+
Some tests produce non-TAP13 output, which is compared to a reference file.
69+
* `luatest` — test suite using the [luatest](https://github.com/tarantool/luatest/) library.
70+
* `unittest` — an executable test file.
71+
72+
* `description`
73+
74+
* `script` — A file with Tarantool commands.
75+
It is used to start the default server using `tarantoolctl`.
76+
The value should be a file in the same directory as `suite.ini`, like `box.lua` or `master.lua`.
77+
This setting is mandatory for suites with diff-tests (`core = tarantool`)
78+
and ignored with other types of tests.
79+
80+
* `config` — name of a test configuration file, for example, `engine.cfg`.
81+
For details, see the [test configuration](#test-configuration) section below.
82+
83+
* `lua_libs` — paths to Lua files that should be copied to the directory,
84+
where a server is started. For example:
85+
86+
```ini
87+
lua_libs = lua/require_mod.lua lua/serializer_test.lua lua/process_timeout.lua
88+
```
89+
90+
### Disabling and skipping tests
91+
92+
A number of fields are used to disable certain tests:
93+
94+
* `disabled` — list of tests that should be skipped.
95+
96+
* `release_disabled` — list of tests that should only run when Tarantool is
97+
built in the debug mode (with `-DCMAKE_BUILD_TYPE=Debug` and not `=RelWithDebInfo`).
98+
Tests that use error injections, which are only available in debug builds,
99+
should always be `release_disabled`.
100+
101+
* `valgrind_disabled` — list of tests that should be skipped when Valgrind is enabled
102+
103+
* `long_run` — mark tests as long. Such tests will run only with `--long` option.
104+
105+
```ini
106+
long_run = t1.test.lua t2.test.lua
107+
```
108+
109+
### Other parameters
110+
111+
* `show_reproduce_content` (optional, `True` by default) — when set to `True`,
112+
show the contents of the reproduce file for each failed test.
113+
Reproduce files are not required for investigating results of
114+
tests that run each case in a separate Tarantool instance.
115+
For such tests it makes sense to set `show_reproduce_content = False`.
116+
(Implemented in [#113](https://github.com/tarantool/test-run/issues/113))
117+
118+
* `is_parallel` (optional, `False` by default) — whether the tests in the suite can run in parallel
119+
120+
* `use_unix_sockets` (optional, `False` by default) — use hard-coded UNIX sockets
121+
* `use_unix_sockets_iproto` (optional, `False` by default) — use hard-coded UNIX sockets for IProto.
122+
123+
### Fragile tests
124+
125+
Tests which fail sometimes due to external reasons can be marked as fragile (flaky).
126+
Test-run will retry each test if it fails.
127+
It's recommended to provide a list of related
128+
[tarantool/tarantool](https://github.com/tarantool/tarantool) issues
129+
next to each fragile test.
130+
131+
```ini
132+
fragile = {
133+
"retries": 10,
134+
"tests": {
135+
"tarantoolctl.test.lua": {
136+
"issues": [ "gh-5059", "gh-5346" ],
137+
},
138+
{...},
139+
{...},
140+
}
141+
}
142+
```
143+
144+
## Test composition
145+
146+
Each test consists of the following files:
147+
148+
* Test file: `<name>.test.lua`, `<name>_test.lua`, `<name>.test.py`, or `<name>.test.sql`.
149+
* Reference file: `<name>.result`.
150+
* Skip condition file: `<name>.skipcond`.
151+
152+
Reference file contains saved test output.
153+
It is required for tests with non-TAP13 output.
154+
Running `test-run.py` with `--update-result` option will update
155+
the `.result` files with new test output.
156+
157+
The optional skip condition file is a Python script.
158+
In the local Python environment of a test run there's a `self` object,
159+
which is an instance of the [`Test` class](./lib/test.py).
160+
Set `self.skip = 1` to skip this test.
161+
162+
163+
## Test execution
164+
165+
Running a test begins with executing the `.skipcond` file.
166+
If `self.skip` is set to `1`, test-run skips this test
167+
and reports TODO.
168+
169+
Next, the test file is executed and the output is written to a `.reject` file.
170+
If the output is TAP13-compatible, test-run validates it.
171+
Otherwise, test-run compares it with the `.result` file.
172+
If there's a difference between `.reject` and `.result`, the test fails and
173+
the last 15 lines of diff are printed to output.
174+
175+
Whenever a test fails, the `.reject` file is saved in the `<vardir>/rejects/<suite>`
176+
subdirectory given in options or set locally as `var/rejects/<suite>` by default.
177+
If the test is considered successful, the `.reject` file is deleted.
178+
179+
## Test configuration
180+
181+
Test configuration file contains configuration for multiple runs.
182+
For each test section, system runs a separate test and compares the result to the common `.result` file.
183+
For example, we need to run a test with different DB engines (`"*"` means the default
50184
configuration):
51185

52186
```json
@@ -62,15 +196,15 @@ configuration):
62196
}
63197
```
64198

65-
In test case we can get configuration from inspector:
199+
In the test case we can get configuration from the inspector:
66200

67201
```lua
68202
engine = test_run:get_cfg('engine')
69203
-- first run engine is 'memtx'
70204
-- second run engine is 'sophia'
71205
```
72206

73-
"engine" value has a special meaning for *.test.sql files: if it is "memtx" or
207+
"engine" value has a special meaning for `*.test.sql` files: if it is "memtx" or
74208
"vinyl", then the corresponding default engine will be set before executing
75209
commands from a test file. An engine is set with the following commands:
76210

@@ -79,11 +213,13 @@ UPDATE "_session_settings" SET "value" = 'memtx|vinyl' WHERE "name" = 'sql_defau
79213
pragma sql_default_engine='memtx|vinyl'
80214
```
81215

82-
If the first fails, then the second will be executed. When both fails, fail the test.
216+
If the first fails, then the second will be executed. When both fail, the test fails.
217+
218+
## Writing various types of tests
83219

84-
#### Python
220+
### Python tests
85221

86-
Files: `<name>.test.py`, `<name>.result` and `<name>.skipcond`(optionaly).
222+
Files: `<name>.test.py`, `<name>.result` and `<name>.skipcond` (optionally).
87223

88224
Environment:
89225

@@ -166,14 +302,14 @@ box.info.lsn
166302
...
167303
```
168304

169-
#### Lua
305+
### Lua
170306

171307
Files: `<name>.test.lua`, `<name>.result` and `<name>.skipcond`(optionaly).
172308
Tests interact only with `AdminConnection`. Supports some preprocessor functions (eg `delimiter`)
173309

174310
**Delimiter example:**
175311

176-
```
312+
```lua
177313
env = require('test_run')
178314
test_run = env.new()
179315
box.schema.space.create('temp')
@@ -194,7 +330,7 @@ test
194330

195331
**Delimiter result:**
196332

197-
```
333+
```yaml
198334
env = require('test_run')
199335
test_run = env.new()
200336
box.schema.space.create('temp')
@@ -255,14 +391,14 @@ function echo(...) \
255391
end
256392
```
257393

258-
#### SQL
394+
### SQL
259395

260396
*.test.sql files are just SQL statements written line-by-line.
261397

262398
It is possible to mix SQL and Lua commands using `\set language lua` and `\set
263399
language sql` commands.
264400

265-
##### Interaction with the test environment
401+
## Interaction with the test environment
266402

267403
In lua test you can use `test_run` module to interact with the test
268404
environment.
@@ -337,7 +473,7 @@ test_run:cmd('setopt delimiter ""');
337473
join(test_run, 30)
338474
```
339475

340-
### pretest_clean()
476+
## pretest_clean()
341477

342478
Nothing will be done before a Python test and for `core = unittest`
343479
test suites.
@@ -353,7 +489,7 @@ The following files will be removed:
353489
* `*.inprogress`
354490
* `[0-9]*/`
355491

356-
### Tags
492+
## Tags
357493

358494
Usage:
359495

@@ -409,7 +545,7 @@ Unsupported features:
409545
* Marking unit tests with tags.
410546
* Multiline comments (use singleline ones for now).
411547

412-
### Used By
548+
## Projects that use test-run
413549

414550
- [Tarantool](https://github.com/tarantool/tarantool) - in-memory database and application server
415551
- [memcached](https://github.com/tarantool/memcached) - Memcached protocol 'wrapper' for Tarantool

0 commit comments

Comments
 (0)