Skip to content

Commit 4320b53

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 4320b53

File tree

1 file changed

+68
-49
lines changed

1 file changed

+68
-49
lines changed

Diff for: test/suites/crud_server.lua

+68-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,19 @@ 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+
local fail_msg = 'The crud/vshard modules are not detected, ' ..
75+
'installation via rocks install is required ' ..
76+
'for CRUD testing purposes. You can use ' ..
77+
'<tarantoolctl rocks install crud> or ' ..
78+
'<tt rocks install crud> to install modules'
79+
-- The print output will be captured in the logs.
80+
print(fail_msg)
81+
-- Because of the implementation of the testing framework,
82+
-- this will cause the crash of the CRUD test and display to user
83+
-- a message about require fail during instance configuration.
84+
box.info.status = fail_msg
85+
else
86+
configure_crud_instance(primary_listen, crud, vshard)
87+
end

0 commit comments

Comments
 (0)