Skip to content

Commit f1bb57c

Browse files
committed
test: fixes the moduleless error of crud instance
In crud tests, if the necessary rocks dependencies are missing, an error message is now displayed. Prior to this fix, an error in importing missing models caused the tests to freez forever. Part of #205
1 parent 30d5fca commit f1bb57c

File tree

2 files changed

+72
-49
lines changed

2 files changed

+72
-49
lines changed

Diff for: test/suites/crud_server.lua

+66-49
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
11
#!/usr/bin/env tarantool
22

3-
local crud = require('crud')
4-
local vshard = require('vshard')
3+
local function configure_crud_instance(primary_listen, crud, vshard)
4+
box.schema.create_space(
5+
'tester', {
6+
format = {
7+
{name = 'id', type = 'unsigned'},
8+
{name = 'bucket_id', type = 'unsigned'},
9+
{name = 'name', type = 'string'},
10+
}
11+
})
12+
box.space.tester:create_index('primary_index', {
13+
parts = {
14+
{field = 1, type = 'unsigned'},
15+
},
16+
})
17+
box.space.tester:create_index('bucket_id', {
18+
parts = {
19+
{field = 2, type = 'unsigned'},
20+
},
21+
unique = false,
22+
})
23+
24+
-- Setup vshard.
25+
_G.vshard = vshard
26+
box.once('guest', function()
27+
box.schema.user.grant('guest', 'super')
28+
end)
29+
local uri = '[email protected]:' .. primary_listen
30+
local cfg = {
31+
bucket_count = 300,
32+
sharding = {
33+
[box.info().cluster.uuid] = {
34+
replicas = {
35+
[box.info().uuid] = {
36+
uri = uri,
37+
name = 'storage',
38+
master = true,
39+
},
40+
},
41+
},
42+
},
43+
}
44+
vshard.storage.cfg(cfg, box.info().uuid)
45+
vshard.router.cfg(cfg)
46+
vshard.router.bootstrap()
47+
48+
-- Initialize crud.
49+
crud.init_storage()
50+
crud.init_router()
51+
crud.cfg{stats = true}
52+
end
53+
54+
local crud_imported, crud = pcall(require, 'crud')
55+
local vshard_imported, vshard = pcall(require, 'vshard')
556

657
local admin_listen = os.getenv("ADMIN")
758
local primary_listen = os.getenv("LISTEN")
@@ -18,51 +69,17 @@ box.schema.user.grant(
1869
'read,write,execute',
1970
'universe'
2071
)
21-
box.schema.create_space(
22-
'tester', {
23-
format = {
24-
{name = 'id', type = 'unsigned'},
25-
{name = 'bucket_id', type = 'unsigned'},
26-
{name = 'name', type = 'string'},
27-
}
28-
})
29-
box.space.tester:create_index('primary_index', {
30-
parts = {
31-
{field = 1, type = 'unsigned'},
32-
},
33-
})
34-
box.space.tester:create_index('bucket_id', {
35-
parts = {
36-
{field = 2, type = 'unsigned'},
37-
},
38-
unique = false,
39-
})
40-
41-
-- Setup vshard.
42-
_G.vshard = vshard
43-
box.once('guest', function()
44-
box.schema.user.grant('guest', 'super')
45-
end)
46-
local uri = '[email protected]:' .. primary_listen
47-
local cfg = {
48-
bucket_count = 300,
49-
sharding = {
50-
[box.info().cluster.uuid] = {
51-
replicas = {
52-
[box.info().uuid] = {
53-
uri = uri,
54-
name = 'storage',
55-
master = true,
56-
},
57-
},
58-
},
59-
},
60-
}
61-
vshard.storage.cfg(cfg, box.info().uuid)
62-
vshard.router.cfg(cfg)
63-
vshard.router.bootstrap()
6472

65-
-- Initialize crud.
66-
crud.init_storage()
67-
crud.init_router()
68-
crud.cfg{stats = true}
73+
if crud_imported == false or vshard_imported == false then
74+
-- Set flag for unittest.
75+
_G['ROCKS_IMPORT_FAIL'] = true
76+
local fail_msg = 'The crud/vshard modules are not detected, ' ..
77+
'installation via rocks install is required ' ..
78+
'for CRUD testing purposes. You can use ' ..
79+
'<tarantoolctl rocks install crud> or ' ..
80+
'<tt rocks install crud> to install modules'
81+
-- The print output will be captured in the logs.
82+
print(fail_msg)
83+
else
84+
configure_crud_instance(primary_listen, crud, vshard)
85+
end

Diff for: test/suites/test_crud.py

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ def setUp(self):
4040
user='guest', password='')
4141
# Time for vshard group configuration.
4242
time.sleep(1)
43+
if self.conn.eval('return ROCKS_IMPORT_FAIL').data[0] == True:
44+
raise unittest.SkipTest('The crud/vshard modules are not detected, ' +
45+
'installation via rocks install is required ' +
46+
'for CRUD testing purposes. You can use ' +
47+
'<tarantoolctl rocks install crud> or ' +
48+
'<tt rocks install crud> to install modules')
4349

4450
crud_test_cases = {
4551
'crud_insert': {

0 commit comments

Comments
 (0)