Skip to content

Commit 525a1a8

Browse files
test: assert admin commands success
Admin command are sent through text protocol. Responses are rarely processed, especially those which sets up schema and users. But such requests can contain errors, like "already exists" or syntax ones. Having asserts on schema set up makes it easier to debug some cases. For example, it was helpful in discovering the reason behind "user not exists" fails fixed in "wait until server is ready" patchset commit [1]. 1. https://github.com/tarantool/tarantool-python/actions/runs/5784619729/job/15675655683?pr=306
1 parent 43880dd commit 525a1a8

15 files changed

+340
-231
lines changed

test/suites/test_connection.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
import sys
77
import unittest
8-
98
import decimal
9+
10+
import pkg_resources
1011
import msgpack
1112

1213
import tarantool
1314
import tarantool.msgpack_ext.decimal as ext_decimal
1415

1516
from .lib.skip import skip_or_run_decimal_test, skip_or_run_varbinary_test
1617
from .lib.tarantool_server import TarantoolServer
18+
from .utils import assert_admin_success
1719

1820

1921
class TestSuiteConnection(unittest.TestCase):
@@ -26,35 +28,45 @@ def setUpClass(cls):
2628
cls.srv.start()
2729

2830
cls.adm = cls.srv.admin
29-
cls.adm(r"""
31+
resp = cls.adm("""
3032
box.schema.user.create('test', {password = 'test', if_not_exists = true})
3133
box.schema.user.grant('test', 'read,write,execute', 'universe')
3234
33-
box.schema.create_space('space_varbin')
34-
35-
box.space['space_varbin']:format({
36-
{
37-
'id',
38-
type = 'number',
39-
is_nullable = false
40-
},
41-
{
42-
'varbin',
43-
type = 'varbinary',
44-
is_nullable = false,
45-
}
46-
})
47-
48-
box.space['space_varbin']:create_index('id', {
49-
type = 'tree',
50-
parts = {1, 'number'},
51-
unique = true})
52-
53-
box.space['space_varbin']:create_index('varbin', {
54-
type = 'tree',
55-
parts = {2, 'varbinary'},
56-
unique = true})
35+
return true
5736
""")
37+
assert_admin_success(resp)
38+
39+
if cls.srv.admin.tnt_version >= pkg_resources.parse_version('2.2.1'):
40+
resp = cls.adm("""
41+
box.schema.create_space('space_varbin')
42+
43+
box.space['space_varbin']:format({
44+
{
45+
'id',
46+
type = 'number',
47+
is_nullable = false
48+
},
49+
{
50+
'varbin',
51+
type = 'varbinary',
52+
is_nullable = false,
53+
}
54+
})
55+
56+
box.space['space_varbin']:create_index('id', {
57+
type = 'tree',
58+
parts = {1, 'number'},
59+
unique = true})
60+
61+
box.space['space_varbin']:create_index('varbin', {
62+
type = 'tree',
63+
parts = {2, 'varbinary'},
64+
unique = true})
65+
66+
return true
67+
""")
68+
assert_admin_success(resp)
69+
5870
cls.con = None
5971

6072
def setUp(self):

test/suites/test_datetime.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .lib.tarantool_server import TarantoolServer
1818
from .lib.skip import skip_or_run_datetime_test, skip_or_run_datetime_2_11_test
19+
from .utils import assert_admin_success
1920

2021

2122
class TestSuiteDatetime(unittest.TestCase):
@@ -28,7 +29,7 @@ def setUpClass(cls):
2829
cls.srv.start()
2930

3031
cls.adm = cls.srv.admin
31-
cls.adm(r"""
32+
resp = cls.adm("""
3233
_, datetime = pcall(require, 'datetime')
3334
3435
box.schema.space.create('test')
@@ -57,7 +58,10 @@ def setUpClass(cls):
5758
return arg1 - arg2
5859
end
5960
rawset(_G, 'sub', sub)
61+
62+
return true
6063
""")
64+
assert_admin_success(resp)
6165

6266
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
6367
user='test', password='test')
@@ -67,7 +71,11 @@ def setUp(self):
6771
if self.srv.is_started():
6872
self.srv.touch_lock()
6973

70-
self.adm("box.space['test']:truncate()")
74+
resp = self.adm("""
75+
box.space['test']:truncate()
76+
return true
77+
""")
78+
assert_admin_success(resp)
7179

7280
def test_datetime_class_api(self):
7381
datetime = tarantool.Datetime(year=2022, month=8, day=31, hour=18, minute=7, sec=54,

test/suites/test_dbapi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from tarantool import dbapi
1313
from .lib.tarantool_server import TarantoolServer
1414
from .lib.skip import skip_or_run_sql_test
15+
from .utils import assert_admin_success
1516

1617

1718
class TestSuiteDBAPI(dbapi20.DatabaseAPI20Test):
@@ -39,17 +40,20 @@ def setUpClass(cls):
3940
"port": cls.srv.args['primary']
4041
}
4142

43+
# grant full access to guest
44+
resp = cls.srv.admin("""
45+
box.schema.user.grant('guest', 'create,read,write,execute', 'universe')
46+
return true
47+
""")
48+
assert_admin_success(resp)
49+
4250
@skip_or_run_sql_test
4351
def setUp(self):
4452
# prevent a remote tarantool from clean our session
4553
if self.srv.is_started():
4654
self.srv.touch_lock()
4755
self.con.flush_schema()
4856

49-
# grant full access to guest
50-
self.srv.admin("box.schema.user.grant('guest', 'create,read,write,"
51-
"execute', 'universe')")
52-
5357
@classmethod
5458
def tearDownClass(cls):
5559
cls.con.close()

test/suites/test_decimal.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .lib.tarantool_server import TarantoolServer
1818
from .lib.skip import skip_or_run_decimal_test
19+
from .utils import assert_admin_success
1920

2021

2122
class TestSuiteDecimal(unittest.TestCase):
@@ -28,7 +29,7 @@ def setUpClass(cls):
2829
cls.srv.start()
2930

3031
cls.adm = cls.srv.admin
31-
cls.adm(r"""
32+
resp = cls.adm("""
3233
_, decimal = pcall(require, 'decimal')
3334
3435
box.schema.space.create('test')
@@ -47,7 +48,10 @@ def setUpClass(cls):
4748
4849
box.schema.user.create('test', {password = 'test', if_not_exists = true})
4950
box.schema.user.grant('test', 'read,write,execute', 'universe')
51+
52+
return true
5053
""")
54+
assert_admin_success(resp)
5155

5256
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
5357
user='test', password='test')
@@ -57,7 +61,11 @@ def setUp(self):
5761
if self.srv.is_started():
5862
self.srv.touch_lock()
5963

60-
self.adm("box.space['test']:truncate()")
64+
resp = self.adm("""
65+
box.space['test']:truncate()
66+
return true
67+
""")
68+
assert_admin_success(resp)
6169

6270
valid_cases = {
6371
'simple_decimal_1': {

test/suites/test_dml.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .lib.tarantool_server import TarantoolServer
1212
from .lib.skip import skip_or_run_error_extra_info_test
13+
from .utils import assert_admin_success
1314

1415

1516
class TestSuiteRequest(unittest.TestCase):
@@ -23,28 +24,31 @@ def setUpClass(cls):
2324
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'])
2425
cls.adm = cls.srv.admin
2526
cls.space_created = cls.adm("box.schema.create_space('space_1')")
26-
cls.adm("""
27-
box.space['space_1']:create_index('primary', {
28-
type = 'tree',
29-
parts = {1, 'num'},
30-
unique = true})
31-
""".replace('\n', ' '))
32-
cls.adm("""
33-
box.space['space_1']:create_index('secondary', {
34-
type = 'tree',
35-
parts = {2, 'num', 3, 'str'},
36-
unique = false})
37-
""".replace('\n', ' '))
38-
cls.space_created = cls.adm("box.schema.create_space('space_2')")
39-
cls.adm("""
40-
box.space['space_2']:create_index('primary', {
41-
type = 'hash',
42-
parts = {1, 'num'},
43-
unique = true})
44-
""".replace('\n', ' '))
45-
cls.adm("json = require('json')")
46-
cls.adm("fiber = require('fiber')")
47-
cls.adm("uuid = require('uuid')")
27+
resp = cls.adm("""
28+
box.space['space_1']:create_index('primary', {
29+
type = 'tree',
30+
parts = {1, 'num'},
31+
unique = true})
32+
33+
box.space['space_1']:create_index('secondary', {
34+
type = 'tree',
35+
parts = {2, 'num', 3, 'str'},
36+
unique = false})
37+
38+
box.schema.create_space('space_2')
39+
40+
box.space['space_2']:create_index('primary', {
41+
type = 'hash',
42+
parts = {1, 'num'},
43+
unique = true})
44+
45+
json = require('json')
46+
fiber = require('fiber')
47+
uuid = require('uuid')
48+
49+
return true
50+
""")
51+
assert_admin_success(resp)
4852

4953
if not sys.platform.startswith("win"):
5054
cls.sock_srv = TarantoolServer(create_unix_socket=True)
@@ -311,7 +315,7 @@ def test_11_select_all_hash(self):
311315
space.select((), iterator=tarantool.const.ITERATOR_EQ)
312316

313317
def test_12_update_fields(self):
314-
self.srv.admin(
318+
resp = self.srv.admin(
315319
"""
316320
do
317321
local sp = box.schema.create_space('sp', {
@@ -325,7 +329,9 @@ def test_12_update_fields(self):
325329
parts = {1, 'unsigned'}
326330
})
327331
end
332+
return true
328333
""")
334+
assert_admin_success(resp)
329335
self.con.insert('sp', [2, 'help', 4])
330336
self.assertSequenceEqual(
331337
self.con.update('sp', (2,), [('+', 'thi', 3)]),

test/suites/test_encoding.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
"""
22
This module tests various type encoding cases.
33
"""
4-
# pylint: disable=missing-class-docstring,missing-function-docstring
4+
# pylint: disable=missing-class-docstring,missing-function-docstring,duplicate-code
55

66
import sys
77
import unittest
8+
import pkg_resources
89

910
import tarantool
1011
from tarantool.error import DatabaseError
1112

1213
from .lib.skip import skip_or_run_varbinary_test, skip_or_run_error_extra_info_test
1314
from .lib.tarantool_server import TarantoolServer
15+
from .utils import assert_admin_success
1416

1517

1618
class TestSuiteEncoding(unittest.TestCase):
@@ -24,52 +26,58 @@ def setUpClass(cls):
2426
cls.srv.script = 'test/suites/box.lua'
2527
cls.srv.start()
2628

27-
cls.srv.admin("""
29+
resp = cls.srv.admin("""
2830
box.schema.user.create('test', { password = 'test' })
2931
box.schema.user.grant('test', 'execute,read,write', 'universe')
32+
33+
return true
3034
""")
35+
assert_admin_success(resp)
3136

3237
args = [cls.srv.host, cls.srv.args['primary']]
3338
kwargs = {'user': 'test', 'password': 'test'}
3439
cls.con_encoding_utf8 = tarantool.Connection(*args, encoding='utf-8', **kwargs)
3540
cls.con_encoding_none = tarantool.Connection(*args, encoding=None, **kwargs)
3641
cls.conns = [cls.con_encoding_utf8, cls.con_encoding_none]
3742

38-
cls.srv.admin("box.schema.create_space('space_str')")
39-
cls.srv.admin("""
43+
resp = cls.srv.admin("""
44+
box.schema.create_space('space_str')
4045
box.space['space_str']:create_index('primary', {
4146
type = 'tree',
4247
parts = {1, 'str'},
4348
unique = true})
44-
""".replace('\n', ' '))
45-
46-
cls.srv.admin("box.schema.create_space('space_varbin')")
47-
cls.srv.admin(r"""
48-
box.space['space_varbin']:format({
49-
{
50-
'id',
51-
type = 'number',
52-
is_nullable = false
53-
},
54-
{
55-
'varbin',
56-
type = 'varbinary',
57-
is_nullable = false,
58-
}
59-
})
60-
""".replace('\n', ' '))
61-
cls.srv.admin("""
62-
box.space['space_varbin']:create_index('id', {
63-
type = 'tree',
64-
parts = {1, 'number'},
65-
unique = true})
66-
""".replace('\n', ' '))
67-
cls.srv.admin("""
68-
box.space['space_varbin']:create_index('varbin', {
69-
type = 'tree',
70-
parts = {2, 'varbinary'},
71-
unique = true})
72-
""".replace('\n', ' '))
49+
50+
return true
51+
""")
52+
assert_admin_success(resp)
53+
54+
if cls.srv.admin.tnt_version >= pkg_resources.parse_version('2.2.1'):
55+
resp = cls.srv.admin("""
56+
box.schema.create_space('space_varbin')
57+
box.space['space_varbin']:format({
58+
{
59+
'id',
60+
type = 'number',
61+
is_nullable = false
62+
},
63+
{
64+
'varbin',
65+
type = 'varbinary',
66+
is_nullable = false,
67+
}
68+
})
69+
box.space['space_varbin']:create_index('id', {
70+
type = 'tree',
71+
parts = {1, 'number'},
72+
unique = true})
73+
box.space['space_varbin']:create_index('varbin', {
74+
type = 'tree',
75+
parts = {2, 'varbinary'},
76+
unique = true})
77+
78+
return true
79+
""")
80+
assert_admin_success(resp)
7381

7482
def assertNotRaises(self, func, *args, **kwargs):
7583
try:

0 commit comments

Comments
 (0)