Skip to content

Commit 605ef94

Browse files
test: migrate to luatest
Rewrite existing regression and performance tests using luatest [1] instead of tap. luatest is a modern tool to write tests for Tarantool core and modules. It is expected for all new tests introduced to the core to be written with luatest, so we rework this before embedding. Add Makefile targets to install and clean dependencies. 1. https://github.com/tarantool/luatest Part of tarantool/tarantool#7726
1 parent f5839d4 commit 605ef94

File tree

3 files changed

+987
-390
lines changed

3 files changed

+987
-390
lines changed

Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
TTCTL := tt
2+
ifeq (,$(shell which tt 2>/dev/null))
3+
TTCTL := tarantoolctl
4+
endif
5+
6+
.PHONY: all
17
all:
2-
@echo "Only tests are available: make test"
8+
@echo "Available commands: .rocks, test, perf, clean"
9+
10+
.rocks: rockspecs/checks-scm-1.rockspec
11+
$(TTCTL) rocks make
12+
$(TTCTL) rocks install luatest 0.5.7
313

4-
test:
5-
./test.lua
14+
.PHONY: test
15+
test: .rocks
16+
.rocks/bin/luatest -c -v ./test.lua
617

18+
.PHONY: perf
719
perf:
8-
./perftest.lua
20+
.rocks/bin/luatest -c ./perftest.lua
21+
22+
.PHONY: clean
23+
clean:
24+
rm -rf .rocks

perftest.lua

Lines changed: 129 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env tarantool
22

3-
require('strict').on()
4-
local tap = require('tap')
3+
local t = require('luatest')
4+
5+
local checks = require('checks')
56
local json = require('json')
7+
local log = require('log')
68
local uuid = require('uuid')
7-
local checks = require('checks')
8-
local test = tap.test('performance_test')
99

10-
local total_time = 0
11-
local total_iter = 0
10+
local g = t.group('checks_performance')
1211

1312
local args = {
1413
['nil'] = nil,
@@ -23,59 +22,138 @@ local args = {
2322
['uuid_bin'] = uuid.bin(),
2423
}
2524

26-
local function perftest(check, argtype)
27-
local fn = function(arg)
28-
checks(check)
29-
end
25+
local cases = {
26+
{
27+
check = '?',
28+
argtype = 'nil',
29+
},
30+
{
31+
check = '?',
32+
argtype = 'nil',
33+
},
3034

31-
local arg = args[argtype]
35+
{
36+
check = 'string',
37+
argtype = 'string',
38+
},
3239

33-
local cnt = 0
34-
local batch_size = 1000
35-
local stop
36-
local start = os.clock()
37-
repeat
38-
for i = 1, batch_size do
39-
fn(arg)
40-
end
41-
cnt = cnt + batch_size
42-
batch_size = math.floor(batch_size * 1.2)
43-
stop = os.clock()
44-
until stop - start > 1
40+
{
41+
check = '?string',
42+
argtype = 'nil',
43+
},
44+
{
45+
check = '?string',
46+
argtype = 'string',
47+
},
4548

46-
local testname = string.format('checks(%s) (%s)', json.encode(check), argtype)
47-
test:diag(string.format(" %-35s: %.2f calls/s", testname, cnt/(stop-start) ))
48-
end
49+
{
50+
check = 'number|string',
51+
argtype = 'string',
52+
},
53+
{
54+
check = 'number|string',
55+
argtype = 'number',
56+
},
4957

50-
perftest('?', 'nil')
51-
perftest('?', 'string')
58+
{
59+
check = 'meta',
60+
argtype = 'meta',
61+
},
62+
{
63+
check = '?string|meta',
64+
argtype = 'nil',
65+
},
66+
{
67+
check = '?string|meta',
68+
argtype = 'string',
69+
},
70+
{
71+
check = '?string|meta',
72+
argtype = 'meta',
73+
},
5274

53-
perftest('string', 'string')
75+
{
76+
check = 'int64',
77+
argtype = 'number',
78+
},
79+
{
80+
check = 'int64',
81+
argtype = 'int64',
82+
},
83+
{
84+
check = 'int64',
85+
argtype = 'uint64',
86+
},
87+
{
88+
check = 'uint64',
89+
argtype = 'number',
90+
},
91+
{
92+
check = 'uint64',
93+
argtype = 'int64',
94+
},
95+
{
96+
check = 'uint64',
97+
argtype = 'uint64',
98+
},
5499

55-
perftest('?string', 'nil')
56-
perftest('?string', 'string')
100+
{
101+
check = 'uuid',
102+
argtype = 'uuid',
103+
},
104+
{
105+
check = 'uuid_str',
106+
argtype = 'uuid_str',
107+
},
108+
{
109+
check = 'uuid_bin',
110+
argtype = 'uuid_bin',
111+
},
57112

58-
perftest('number|string', 'string')
59-
perftest('number|string', 'number')
113+
{
114+
check = {x='?'},
115+
argtype = 'table',
116+
},
117+
{
118+
check = {x={y='?'}},
119+
argtype = 'table',
120+
},
121+
{
122+
check = {x={y={z='?'}}},
123+
argtype = 'table',
124+
},
125+
{
126+
check = {x={y={z={t='?'}}}},
127+
argtype = 'table',
128+
},
129+
-- TODO checks({timeout = '?number'}) -- table checker
130+
}
131+
132+
for _, case in pairs(cases) do
133+
-- dots in test case name are not expected
134+
local name = ('test_%s_%s'):format(json.encode(case.check), case.argtype):gsub('%.', '_')
60135

61-
perftest('meta', 'meta')
62-
perftest('?string|meta', 'nil')
63-
perftest('?string|meta', 'string')
64-
perftest('?string|meta', 'meta')
136+
g[name] = function(_)
137+
local fn = function(arg) -- luacheck: no unused args
138+
checks(case.check)
139+
end
65140

66-
perftest('int64', 'number')
67-
perftest('int64', 'int64')
68-
perftest('int64', 'uint64')
69-
perftest('uint64', 'number')
70-
perftest('uint64', 'int64')
71-
perftest('uint64', 'uint64')
141+
local arg = args[case.argtype]
72142

73-
perftest('uuid', 'uuid')
74-
perftest('uuid_str', 'uuid_str')
75-
perftest('uuid_bin', 'uuid_bin')
143+
local cnt = 0
144+
local batch_size = 1000
145+
local stop
146+
local start = os.clock()
147+
repeat
148+
for _ = 1, batch_size do
149+
fn(arg)
150+
end
151+
cnt = cnt + batch_size
152+
batch_size = math.floor(batch_size * 1.2)
153+
stop = os.clock()
154+
until stop - start > 1
76155

77-
perftest({x='?'}, 'table')
78-
perftest({x={y='?'}}, 'table')
79-
perftest({x={y={z='?'}}}, 'table')
80-
perftest({x={y={z={t='?'}}}}, 'table')
81-
-- TODO checks({timeout = '?number'}) -- table checker
156+
local testline = string.format('checks(%s) (%s)', json.encode(case.check), case.argtype)
157+
log.info(" %-35s: %.2f calls/s", testline, cnt / (stop - start))
158+
end
159+
end

0 commit comments

Comments
 (0)