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

Commit a070f5b

Browse files
committed
Support shard-2.1 (when will be released)
Fixed running on several shard configuration in test/common suite. * Fixed #61. * Related to #111. TBD: test/shard_* is not working because of cluster dropping.
1 parent dd27668 commit a070f5b

12 files changed

+105
-260
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ make test
101101
* tarantool,
102102
* lulpeg,
103103
* >=tarantool/avro-schema-2.0-71-gfea0ead,
104-
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) (optional),
104+
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) or >=tarantool/shard-2.1
105+
(when will be released) (optional),
105106
* lrexlib-pcre2 or lrexlib-pcre (optional).
106107
* For test (additionally to 'for use'):
107108
* python 2.7,
108109
* virtualenv,
109110
* luacheck,
110-
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0),
111+
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0) or >=tarantool/shard-2.1
112+
(when will be released),
111113
* >=tarantool/avro-schema-2.2.2-4-g1145e3e.
112114
* For building apidoc (additionally to 'for use'):
113115
* ldoc.

graphql/accessor_shard.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22
--- (@{accessor_general}) behaves as shard accessor and provides the
33
--- `accessor_shard.new` function to create a new shard data accessor instance.
44

5+
local json = require('json')
56
local shard = require('shard')
67
local accessor_general = require('graphql.accessor_general')
78

89
local accessor_shard = {}
910

1011
local LIMIT = 100000 -- XXX: we need to raise an error when a limit reached
1112

13+
local function shard_check_error(func_name, result, err)
14+
if result ~= nil then return end
15+
error(('%s: %s'):format(func_name, json.encode(err)))
16+
end
17+
1218
-- Check whether a collection (it is sharded space for that accessor) exists.
1319
local function is_collection_exists(collection_name)
20+
local func_name = 'accessor_shard.is_collection_exists'
1421
local exists
1522
for _, zone in ipairs(shard.shards) do
1623
for _, node in ipairs(zone) do
17-
local cur = shard:space_call(collection_name, node,
24+
local cur, err = shard:space_call(collection_name, node,
1825
function(space_obj)
1926
return space_obj ~= nil
2027
end)
28+
shard_check_error(func_name, cur, err)
2129
assert(exists == nil or cur == exists,
2230
('space "%s" exists on some shards, ' ..
2331
'but does not on others'):format(collection_name))
@@ -31,13 +39,15 @@ end
3139
--- determining whether the index exists within a shard cluster is
3240
--- not-so-trivial as for local spaces.
3341
local function is_index_exists(collection_name, index_name)
42+
local func_name = 'accessor_shard.is_index_exists'
3443
local exists
3544
for _, zone in ipairs(shard.shards) do
3645
for _, node in ipairs(zone) do
37-
local cur = shard:space_call(collection_name, node,
46+
local cur, err = shard:space_call(collection_name, node,
3847
function(space_obj)
3948
return space_obj.index[index_name] ~= nil
4049
end)
50+
shard_check_error(func_name, cur, err)
4151
assert(exists == nil or cur == exists,
4252
('index "%s" of space "%s" exists on some shards, ' ..
4353
'but does not on others'):format(index_name, collection_name))
@@ -57,10 +67,12 @@ local function get_index(collection_name, index_name)
5767
local index = setmetatable({}, {
5868
__index = {
5969
pairs = function(self, value, opts)
70+
local func_name = 'accessor_shard.get_index.<index>.pairs'
6071
local opts = opts or {}
6172
opts.limit = opts.limit or LIMIT
62-
local tuples = shard:secondary_select(collection_name,
73+
local tuples, err = shard:secondary_select(collection_name,
6374
index_name, opts, value, 0)
75+
shard_check_error(func_name, tuples, err)
6476
local cur = 1
6577
local function gen()
6678
if cur > #tuples then return nil end

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.

0 commit comments

Comments
 (0)