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

Commit ea859f9

Browse files
committed
Support avro-schema-3* (updated tests)
Changed only tests where a data layout is different between avro-schema-2* and avro-schema-3*. The avro_refs test triggers a flatten bug in avro-schema-2.3.2, so the data flattened manually in the case. The bug is not reported, because it is recomended to move to avro-schema-3* to use record*. Fixes #150.
1 parent 1fc8acc commit ea859f9

15 files changed

+377
-156
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ dist: trusty
77
env:
88
- SHARD_VERSION=1.2 AVRO_SCHEMA=2.3.2
99
- SHARD_VERSION=2.1 AVRO_SCHEMA=2.3.2
10+
- SHARD_VERSION=1.2 AVRO_SCHEMA=3.0.0
11+
- SHARD_VERSION=2.1 AVRO_SCHEMA=3.0.0
1012

1113
branches:
1214
only:

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ make test
215215
* For use:
216216
* tarantool,
217217
* lulpeg,
218-
* >=tarantool/avro-schema-2.0-71-gfea0ead (but < 3.0.0),
218+
* >=tarantool/avro-schema-2.0-71-gfea0ead,
219219
* >=tarantool/shard-1.1-91-gfa88bf8 (but < 2.0) or
220220
>=tarantool/shard-2.1-0-g0a7d98f (optional),
221221
* lrexlib-pcre2 or lrexlib-pcre (optional),
@@ -224,7 +224,7 @@ make test
224224
* python 2.7,
225225
* virtualenv,
226226
* luacheck,
227-
* >=tarantool/avro-schema-2.2.2-4-g1145e3e (but < 3.0.0),
227+
* >=tarantool/avro-schema-2.2.2-4-g1145e3e,
228228
* >=tarantool/shard-1.1-92-gec1a27e (but < 2.0) or
229229
>=tarantool/shard-2.1-0-g0a7d98f,
230230
* tarantool/http.

test/common/multirunner.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ local function run_conf(conf_name, opts)
110110

111111
local test_run = opts.test_run
112112
local init_function = opts.init_function
113+
local init_function_params = opts.init_function_params or {}
113114
local cleanup_function = opts.cleanup_function
115+
local cleanup_function_params = opts.cleanup_function_params or {}
114116
local workload = opts.workload
115117
local servers = opts.servers or servers -- prefer opts.servers
116118
local use_tcp = opts.use_tcp or false
117119

118120
assert(init_function ~= nil)
121+
assert(type(init_function_params) == 'table')
119122
assert(cleanup_function ~= nil)
123+
assert(type(cleanup_function_params) == 'table')
120124
assert(workload ~= nil)
121125
assert(use_tcp ~= nil)
122126
if conf_type == 'shard' then
@@ -127,9 +131,9 @@ local function run_conf(conf_name, opts)
127131
local result
128132

129133
if conf_type == 'space' then
130-
init_function()
134+
init_function(unpack(init_function_params))
131135
result = workload(conf_name, nil)
132-
cleanup_function()
136+
cleanup_function(unpack(cleanup_function_params))
133137
elseif conf_type == 'shard' then
134138
-- convert functions to string, so, that it can be executed on shards
135139
local init_script = string.dump(init_function)
@@ -139,14 +143,14 @@ local function run_conf(conf_name, opts)
139143

140144
for_each_server(shard, function(uri)
141145
local c = net_box.connect(uri)
142-
c:eval(init_script)
146+
c:eval(init_script, init_function_params)
143147
end)
144148

145149
result = workload(conf_name, shard)
146150

147151
for_each_server(shard, function(uri)
148152
local c = net_box.connect(uri)
149-
c:eval(cleanup_script)
153+
c:eval(cleanup_script, cleanup_function_params)
150154
end)
151155

152156
shard_cleanup(test_run, servers)

test/common/mutation.test.lua

+14-20
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
4141
exp_result_insert, opts)
4242
local opts = opts or {}
4343
local dont_pass_variables = opts.dont_pass_variables or false
44+
local meta = opts.meta
45+
4446
utils.show_trace(function()
4547
test:plan(7)
46-
local NULL_T = 0 -- value in tuple to tag NULL value
4748
local user_id = 'user_id_new_1'
4849
local order_id = 'order_id_new_1'
4950
local variables_insert = {
@@ -70,26 +71,14 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
7071
-- check inserted user
7172
local tuple = get_tuple(virtbox, 'user_collection', {user_id})
7273
test:ok(tuple ~= nil, 'tuple was inserted')
73-
local exp_tuple = {
74-
0,
75-
variables_insert.user.user_id,
76-
variables_insert.user.first_name,
77-
NULL_T,
78-
variables_insert.user.middle_name,
79-
variables_insert.user.last_name,
80-
}
74+
local exp_tuple = test_utils.flatten_object(virtbox, meta,
75+
'user_collection', variables_insert.user, {0})
8176
test:is_deeply(tuple:totable(), exp_tuple, 'inserted tuple is correct')
8277
-- check inserted order
8378
local tuple = get_tuple(virtbox, 'order_collection', {order_id})
8479
test:ok(tuple ~= nil, 'tuple was inserted')
85-
local exp_tuple = {
86-
variables_insert.order.order_id,
87-
variables_insert.order.user_id,
88-
variables_insert.order.description,
89-
variables_insert.order.price,
90-
variables_insert.order.discount,
91-
variables_insert.order.in_stock or true,
92-
}
80+
local exp_tuple = test_utils.flatten_object(virtbox, meta,
81+
'order_collection', variables_insert.order)
9382
test:is_deeply(tuple:totable(), exp_tuple, 'inserted tuple is correct')
9483
-- clean up inserted tuples & check
9584
delete_tuple(virtbox, 'user_collection', {user_id})
@@ -102,10 +91,12 @@ local function check_insert(test, gql_wrapper, virtbox, mutation_insert,
10291
end)
10392
end
10493

105-
local function run_queries(gql_wrapper, virtbox)
94+
local function run_queries(gql_wrapper, virtbox, meta)
10695
local test = tap.test('mutation')
10796
test:plan(6)
10897

98+
-- {{{ insert
99+
109100
local mutation_insert_1 = [[
110101
mutation insert_user_and_order($user: user_collection_insert,
111102
$order: order_collection_insert) {
@@ -135,7 +126,7 @@ local function run_queries(gql_wrapper, virtbox)
135126
]]):strip())
136127

137128
check_insert(test:test('insert_1'), gql_wrapper, virtbox, mutation_insert_1,
138-
exp_result_insert_1)
129+
exp_result_insert_1, {meta = meta})
139130

140131
-- the same with immediate argument
141132
local mutation_insert_1i = [[
@@ -165,7 +156,8 @@ local function run_queries(gql_wrapper, virtbox)
165156
]]
166157

167158
check_insert(test:test('insert_1i'), gql_wrapper, virtbox,
168-
mutation_insert_1i, exp_result_insert_1, {dont_pass_variables = true})
159+
mutation_insert_1i, exp_result_insert_1, {meta = meta,
160+
dont_pass_variables = true})
169161

170162
-- test "insert" argument is forbidden in a non-top level field
171163
local mutation_insert_2 = [[
@@ -244,6 +236,8 @@ local function run_queries(gql_wrapper, virtbox)
244236

245237
-- XXX: test inserting an object into a collection with subrecords
246238

239+
-- }}}
240+
247241
-- {{{ inner level inserts: disabled
248242
--[=[
249243

test/extra/to_avro_nested.test.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ box.cfg{wal_mode="none"}
1717
test:plan(4)
1818

1919
data.init_spaces()
20-
data.fill_test_data(box.space)
20+
data.fill_test_data(box.space, data.meta)
2121

2222
local accessor = graphql.accessor_space.new({
2323
schemas = data.meta.schemas,

test/extra/to_avro_nullable.test.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ box.cfg{wal_mode="none"}
1616
test:plan(4)
1717

1818
testdata.init_spaces()
19-
testdata.fill_test_data()
2019
local meta = testdata.get_test_metadata()
20+
testdata.fill_test_data(box.space, meta)
2121

2222
local accessor = graphql.accessor_space.new({
2323
schemas = meta.schemas,

test/space/nested_args.test.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local tap = require('tap')
1111
local yaml = require('yaml')
1212
local graphql = require('graphql')
1313
local utils = require('graphql.utils')
14+
local test_utils = require('test.utils')
1415
local common_testdata = require('test.testdata.common_testdata')
1516
local emails_testdata = require('test.testdata.nullable_1_1_conn_testdata')
1617

@@ -23,12 +24,16 @@ common_testdata.init_spaces()
2324
emails_testdata.init_spaces()
2425

2526
-- upload test data
26-
common_testdata.fill_test_data()
27-
emails_testdata.fill_test_data()
27+
local common_meta = common_testdata.meta or common_testdata.get_test_metadata()
28+
local emails_meta = emails_testdata.meta or emails_testdata.get_test_metadata()
29+
common_testdata.fill_test_data(box.space, common_meta)
30+
emails_testdata.fill_test_data(box.space, emails_meta)
31+
32+
local avro_version = test_utils.major_avro_schema_version()
2833

2934
local LOCALPART_FN = 1
3035
local DOMAIN_FN = 2
31-
local BODY_FN = 7
36+
local BODY_FN = avro_version == 3 and 5 or 7
3237

3338
for _, tuple in box.space.email:pairs() do
3439
local body = tuple[BODY_FN]

test/space/server.test.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ box.cfg{background = false}
1818
testdata.init_spaces()
1919

2020
-- upload test data
21-
testdata.fill_test_data()
21+
local meta = testdata.meta or testdata.get_test_metadata()
22+
testdata.fill_test_data(box.space, meta)
2223

2324
-- acquire metadata
2425
local metadata = testdata.get_test_metadata()

test/space/unflatten_tuple.test.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ local testdata = require('test.testdata.common_testdata')
2121
box.cfg{background = false}
2222
testdata.init_spaces()
2323

24-
-- upload test data
25-
testdata.fill_test_data()
26-
2724
-- acquire metadata
2825
local metadata = testdata.get_test_metadata()
2926
local schemas = metadata.schemas
3027
local collections = metadata.collections
3128
local service_fields = metadata.service_fields
3229
local indexes = metadata.indexes
3330

31+
-- upload test data
32+
testdata.fill_test_data(box.space, metadata)
33+
3434
-- build accessor and graphql schemas
3535
-- ----------------------------------
3636

test/testdata/avro_refs_testdata.lua

+41-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local tap = require('tap')
88
local json = require('json')
99
local yaml = require('yaml')
1010
local utils = require('graphql.utils')
11+
local test_utils = require('test.utils')
1112

1213
local testdata = {}
1314

@@ -94,25 +95,51 @@ function testdata.drop_spaces()
9495
box.space.foo:drop()
9596
end
9697

97-
function testdata.fill_test_data(virtbox)
98-
local NULL_T = 0
99-
local VALUE_T = 1
100-
98+
function testdata.fill_test_data(virtbox, meta)
10199
local x = 1000
102100
local y = 2000
103101
local a = 3000
104102
local b = 4000
105103

106-
-- non-null bar, baz and its refs
107-
virtbox.foo:replace({1, -- id
108-
x, y, x, y, VALUE_T, {x, y}, -- bar & refs
109-
VALUE_T, {a, b}, a, b, VALUE_T, {a, b}, -- baz & refs
110-
})
111-
-- null in nullable bar, baz refs
112-
virtbox.foo:replace({2, -- id
113-
x, y, x, y, NULL_T, box.NULL, -- bar & refs
114-
NULL_T, box.NULL, a, b, NULL_T, box.NULL, -- baz & refs
115-
})
104+
local avro_version = test_utils.major_avro_schema_version()
105+
106+
if avro_version == 3 then
107+
-- non-null bar, baz and its refs
108+
test_utils.replace_object(virtbox, meta, 'foo', {
109+
id = 1,
110+
bar = {x = x, y = y},
111+
bar_ref = {x = x, y = y},
112+
bar_nref = {x = x, y = y},
113+
baz = {x = a, y = b},
114+
baz_ref = {x = a, y = b},
115+
baz_nref = {x = a, y = b},
116+
})
117+
-- null in nullable bar, baz refs
118+
test_utils.replace_object(virtbox, meta, 'foo', {
119+
id = 2,
120+
bar = {x = x, y = y},
121+
bar_ref = {x = x, y = y},
122+
bar_nref = box.NULL,
123+
baz = box.NULL,
124+
baz_ref = {x = a, y = b},
125+
baz_nref = box.NULL,
126+
})
127+
else
128+
-- flatten does not work properly in the case of avro-schema-2.3.2
129+
local NULL_T = 0
130+
local VALUE_T = 1
131+
132+
-- non-null bar, baz and its refs
133+
virtbox.foo:replace({1, -- id
134+
x, y, x, y, VALUE_T, {x, y}, -- bar & refs
135+
VALUE_T, {a, b}, a, b, VALUE_T, {a, b}, -- baz & refs
136+
})
137+
-- null in nullable bar, baz refs
138+
virtbox.foo:replace({2, -- id
139+
x, y, x, y, NULL_T, box.NULL, -- bar & refs
140+
NULL_T, box.NULL, a, b, NULL_T, box.NULL, -- baz & refs
141+
})
142+
end
116143
end
117144

118145
function testdata.run_queries(gql_wrapper)

0 commit comments

Comments
 (0)