Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 2bfd8fe

Browse files
committed
Fixed running on several shard configuration
It is about test/common suite. Fixed #61.
1 parent cf5c318 commit 2bfd8fe

File tree

9 files changed

+82
-251
lines changed

9 files changed

+82
-251
lines changed

test/common/limit_result.test.lua

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,19 @@
11
#!/usr/bin/env tarantool
2-
local multirunner = require('multirunner')
3-
local data = require('test_data_user_order')
4-
local test_run = require('test_run').new()
5-
local tap = require('tap')
6-
local graphql = require('graphql')
72

8-
box.cfg({})
9-
local test = tap.test('result cnt')
10-
test:plan(6)
3+
local fio = require('fio')
114

125
-- require in-repo version of graphql/ sources despite current working directory
13-
local fio = require('fio')
146
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
157
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
168

17-
local function run(setup_name, shard)
18-
print(setup_name)
19-
local accessor_class
20-
local virtbox
21-
-- SHARD
22-
if shard ~= nil then
23-
accessor_class = graphql.accessor_shard
24-
virtbox = shard
25-
else
26-
accessor_class = graphql.accessor_space
27-
virtbox = box.space
28-
end
29-
local accessor = accessor_class.new({
30-
schemas = data.meta.schemas,
31-
collections = data.meta.collections,
32-
service_fields = data.meta.service_fields,
33-
indexes = data.meta.indexes,
34-
resulting_object_cnt_max = 3,
35-
fetched_object_cnt_max = 5
36-
})
9+
local tap = require('tap')
10+
local utils = require('test.utils')
11+
local testdata = require('test.common.lua.test_data_user_order')
12+
13+
local function run_queries(gql_wrapper)
14+
local test = tap.test('result cnt')
15+
test:plan(2)
3716

38-
local gql_wrapper = graphql.new({
39-
schemas = data.meta.schemas,
40-
collections = data.meta.collections,
41-
accessor = accessor,
42-
})
43-
data.fill_test_data(virtbox)
4417
local query = [[
4518
query object_result_max($user_id: Int, $description: String) {
4619
user_collection(id: $user_id) {
@@ -75,12 +48,17 @@ local function run(setup_name, shard)
7548
'count%[6%] exceeds limit%[5%] %(`fetched_object_cnt_max`',
7649
'resulting_object_cnt_max test')
7750

78-
51+
assert(test:check(), 'check plan')
7952
end
8053

81-
multirunner.run(test_run,
82-
data.init_spaces,
83-
data.drop_spaces,
84-
run)
54+
box.cfg({})
55+
56+
utils.run_testdata(testdata, {
57+
run_queries = run_queries,
58+
graphql_opts = {
59+
resulting_object_cnt_max = 3,
60+
fetched_object_cnt_max = 5,
61+
}
62+
})
8563

86-
os.exit(test:check() == true and 0 or 1)
64+
os.exit()

test/common/lua/multirunner.lua

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ local CONFS = {
5858
local initialized = false
5959

6060
local function init_shard(test_run, servers, config, use_tcp)
61+
assert(initialized == false)
62+
6163
local suite = 'common'
6264
local uris = test_run:create_cluster(servers, suite)
6365

@@ -70,17 +72,10 @@ local function init_shard(test_run, servers, config, use_tcp)
7072
end
7173
end
7274

73-
-- XXX: for now we always use one shard configuration (a first one),
74-
-- because it is unclear how to reload shard module with an another
75-
-- configuration; the another way is use several test configurations, but
76-
-- it seems to be non-working in 'core = app' tests with current test-run.
77-
-- Ways to better handle this is subject to future digging.
7875
local shard = require('shard')
79-
if not initialized then
80-
shard.init(config)
81-
initialized = true
82-
end
76+
shard.init(config)
8377
shard.wait_connection()
78+
initialized = true
8479
return shard
8580
end
8681

@@ -160,31 +155,6 @@ local function run_conf(conf_name, opts)
160155
return result
161156
end
162157

163-
-- Run tests on multiple accessors and configurations.
164-
-- Feel free to add more configurations.
165-
local function run(test_run, init_function, cleanup_function, workload)
166-
-- ensure stable order
167-
local names = {}
168-
for conf_name, conf in pairs(CONFS) do
169-
-- allow to run w/o test-run
170-
if test_run ~= nil or conf.type == 'space' then
171-
names[#names + 1] = conf_name
172-
end
173-
end
174-
table.sort(names)
175-
176-
for _, conf_name in ipairs(names) do
177-
run_conf(conf_name, {
178-
test_run = test_run,
179-
init_function = init_function,
180-
cleanup_function = cleanup_function,
181-
workload = workload,
182-
servers = nil,
183-
use_tcp = false,
184-
})
185-
end
186-
end
187-
188158
local function get_conf(conf_name)
189159
local conf = CONFS[conf_name]
190160
assert(conf ~= nil)
@@ -193,6 +163,5 @@ end
193163

194164
return {
195165
run_conf = run_conf,
196-
run = run,
197166
get_conf = get_conf,
198167
}

test/common/lua/test_data_nested_record.lua

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-- https://github.com/tarantool/graphql/issues/46
33
-- https://github.com/tarantool/graphql/issues/49
44

5+
local tap = require('tap')
56
local json = require('json')
67
local yaml = require('yaml')
78
local utils = require('graphql.utils')
@@ -79,7 +80,8 @@ function testdata.fill_test_data(virtbox)
7980
end
8081

8182
function testdata.run_queries(gql_wrapper)
82-
local output = ''
83+
local test = tap.test('nested_record')
84+
test:plan(1)
8385

8486
local query_1 = [[
8587
query getUserByUid($uid: Long) {
@@ -101,12 +103,20 @@ function testdata.run_queries(gql_wrapper)
101103
return gql_query_1:execute(variables_1)
102104
end)
103105

104-
output = output .. 'RUN 1 {{{\n' ..
105-
(('QUERY\n%s'):format(query_1:rstrip())) .. '\n' ..
106-
(('VARIABLES\n%s'):format(yaml.encode(variables_1))) .. '\n' ..
107-
(('RESULT\n%s'):format(yaml.encode(result_1))) .. '\n' ..
108-
'}}}\n'
106+
local exp_result_1 = yaml.decode(([[
107+
---
108+
user:
109+
- uid: 5
110+
p1: p1 5
111+
p2: p2 5
112+
nested:
113+
x: 1005
114+
y: 2005
115+
]]):strip())
109116

117+
test:is_deeply(result_1, exp_result_1, '1')
118+
119+
-- XXX: uncomment when arguments for nested records will be supported
110120
--[=[
111121
local query_2 = [[
112122
query getUserByX($x: Long) {
@@ -128,14 +138,21 @@ function testdata.run_queries(gql_wrapper)
128138
return gql_query_2:execute(variables_2)
129139
end)
130140
131-
output = output .. 'RUN 2 {{{\n' ..
132-
(('QUERY\n%s'):format(query_2:rstrip())) .. '\n' ..
133-
(('VARIABLES\n%s'):format(yaml.encode(variables_2))) .. '\n' ..
134-
(('RESULT\n%s'):format(yaml.encode(result_2))) .. '\n' ..
135-
'}}}\n'
141+
local exp_result_2 = yaml.decode(([[
142+
---
143+
user:
144+
- uid: 5
145+
p1: p1 5
146+
p2: p2 5
147+
nested:
148+
x: 1005
149+
y: 2005
150+
]]):strip())
151+
152+
test:is_deeply(result_2, exp_result_2, '2')
136153
]=]--
137154

138-
return output:rstrip()
155+
assert(test:check(), 'check plan')
139156
end
140157

141158
return testdata

test/common/nested_record.result

Lines changed: 0 additions & 93 deletions
This file was deleted.

test/common/nested_record.test.lua

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,11 @@ local fio = require('fio')
66
package.path = fio.abspath(debug.getinfo(1).source:match("@?(.*/)")
77
:gsub('/./', '/'):gsub('/+$', '')) .. '/../../?.lua' .. ';' .. package.path
88

9-
local multirunner = require('test.common.lua.multirunner')
9+
local utils = require('test.utils')
1010
local testdata = require('test.common.lua.test_data_nested_record')
11-
local graphql = require('graphql')
12-
local utils = require('graphql.utils')
13-
local test_run = utils.optional_require('test_run')
14-
if test_run then
15-
test_run = test_run.new()
16-
end
1711

1812
box.cfg({})
1913

20-
local function run(setup_name, shard)
21-
print(setup_name)
22-
23-
local virtbox = shard or box.space
24-
25-
local gql_wrapper = graphql.new({
26-
schemas = testdata.meta.schemas,
27-
collections = testdata.meta.collections,
28-
service_fields = testdata.meta.service_fields,
29-
indexes = testdata.meta.indexes,
30-
accessor = shard and 'shard' or 'space',
31-
})
32-
33-
testdata.fill_test_data(virtbox)
34-
print(testdata.run_queries(gql_wrapper))
35-
end
36-
37-
multirunner.run(test_run, testdata.init_spaces, testdata.drop_spaces, run)
14+
utils.run_testdata(testdata)
3815

3916
os.exit()

0 commit comments

Comments
 (0)