Skip to content

Commit 5cc07fd

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 5cc07fd

15 files changed

+269
-183
lines changed

test/suites/test_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from .lib.skip import skip_or_run_decimal_test, skip_or_run_varbinary_test
1616
from .lib.tarantool_server import TarantoolServer
17+
from .utils import assert_admin_success
1718

1819

1920
class TestSuiteConnection(unittest.TestCase):
@@ -26,7 +27,7 @@ def setUpClass(cls):
2627
cls.srv.start()
2728

2829
cls.adm = cls.srv.admin
29-
cls.adm(r"""
30+
resp = cls.adm(r"""
3031
box.schema.user.create('test', {password = 'test', if_not_exists = true})
3132
box.schema.user.grant('test', 'read,write,execute', 'universe')
3233
@@ -54,7 +55,10 @@ def setUpClass(cls):
5455
type = 'tree',
5556
parts = {2, 'varbinary'},
5657
unique = true})
58+
59+
return true
5760
""")
61+
assert_admin_success(resp)
5862
cls.con = None
5963

6064
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(r"""
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(r"""
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: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from .lib.skip import skip_or_run_varbinary_test, skip_or_run_error_extra_info_test
1313
from .lib.tarantool_server import TarantoolServer
14+
from .utils import assert_admin_success
1415

1516

1617
class TestSuiteEncoding(unittest.TestCase):
@@ -24,27 +25,28 @@ def setUpClass(cls):
2425
cls.srv.script = 'test/suites/box.lua'
2526
cls.srv.start()
2627

27-
cls.srv.admin("""
28+
resp = cls.srv.admin("""
2829
box.schema.user.create('test', { password = 'test' })
2930
box.schema.user.grant('test', 'execute,read,write', 'universe')
31+
32+
return true
3033
""")
34+
assert_admin_success(resp)
3135

3236
args = [cls.srv.host, cls.srv.args['primary']]
3337
kwargs = {'user': 'test', 'password': 'test'}
3438
cls.con_encoding_utf8 = tarantool.Connection(*args, encoding='utf-8', **kwargs)
3539
cls.con_encoding_none = tarantool.Connection(*args, encoding=None, **kwargs)
3640
cls.conns = [cls.con_encoding_utf8, cls.con_encoding_none]
3741

38-
cls.srv.admin("box.schema.create_space('space_str')")
39-
cls.srv.admin("""
42+
resp = cls.srv.admin("""
43+
box.schema.create_space('space_str')
4044
box.space['space_str']:create_index('primary', {
4145
type = 'tree',
4246
parts = {1, 'str'},
4347
unique = true})
44-
""".replace('\n', ' '))
4548
46-
cls.srv.admin("box.schema.create_space('space_varbin')")
47-
cls.srv.admin(r"""
49+
box.schema.create_space('space_varbin')
4850
box.space['space_varbin']:format({
4951
{
5052
'id',
@@ -57,19 +59,18 @@ def setUpClass(cls):
5759
is_nullable = false,
5860
}
5961
})
60-
""".replace('\n', ' '))
61-
cls.srv.admin("""
6262
box.space['space_varbin']:create_index('id', {
6363
type = 'tree',
6464
parts = {1, 'number'},
6565
unique = true})
66-
""".replace('\n', ' '))
67-
cls.srv.admin("""
6866
box.space['space_varbin']:create_index('varbin', {
6967
type = 'tree',
7068
parts = {2, 'varbinary'},
7169
unique = true})
72-
""".replace('\n', ' '))
70+
71+
return true
72+
""")
73+
assert_admin_success(resp)
7374

7475
def assertNotRaises(self, func, *args, **kwargs):
7576
try:

test/suites/test_error_ext.py

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

1616
from .lib.tarantool_server import TarantoolServer
1717
from .lib.skip import skip_or_run_error_ext_type_test
18+
from .utils import assert_admin_success
1819

1920

2021
class TestSuiteErrorExt(unittest.TestCase):
@@ -27,7 +28,7 @@ def setUpClass(cls):
2728
cls.srv.start()
2829

2930
cls.adm = cls.srv.admin
30-
cls.adm(r"""
31+
resp = cls.adm(r"""
3132
box.schema.space.create('test')
3233
box.space['test']:create_index('primary', {
3334
type = 'tree',
@@ -38,7 +39,10 @@ def setUpClass(cls):
3839
box.schema.user.grant('test', 'read,write,execute,create', 'universe')
3940
4041
box.schema.user.create('no_grants', {if_not_exists = true})
42+
43+
return true
4144
""")
45+
assert_admin_success(resp)
4246

4347
cls.conn_encoding_utf8 = tarantool.Connection(
4448
cls.srv.host, cls.srv.args['primary'],
@@ -78,7 +82,11 @@ def setUp(self):
7882
if self.srv.is_started():
7983
self.srv.touch_lock()
8084

81-
self.adm("box.space['test']:truncate()")
85+
resp = self.adm("""
86+
box.space['test']:truncate()
87+
return true
88+
""")
89+
assert_admin_success(resp)
8290

8391
# msgpack data for different encodings are actually the same,
8492
# but sometimes python msgpack module use different string

test/suites/test_execute.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tarantool
1010
from .lib.tarantool_server import TarantoolServer
1111
from .lib.skip import skip_or_run_sql_test
12+
from .utils import assert_admin_success
1213

1314

1415
class TestSuiteExecute(unittest.TestCase):
@@ -32,17 +33,20 @@ def setUpClass(cls):
3233
cls.srv.start()
3334
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'])
3435

36+
# grant full access to guest
37+
resp = cls.srv.admin("""
38+
box.schema.user.grant('guest', 'create,read,write,execute', 'universe')
39+
return true
40+
""")
41+
assert_admin_success(resp)
42+
3543
@skip_or_run_sql_test
3644
def setUp(self):
3745
# prevent a remote tarantool from clean our session
3846
if self.srv.is_started():
3947
self.srv.touch_lock()
4048
self.con.flush_schema()
4149

42-
# grant full access to guest
43-
self.srv.admin("box.schema.user.grant('guest', 'create,read,write,"
44-
"execute', 'universe')")
45-
4650
@classmethod
4751
def tearDownClass(cls):
4852
cls.con.close()

test/suites/test_interval.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from .lib.tarantool_server import TarantoolServer
2828
from .lib.skip import skip_or_run_datetime_test
29+
from .utils import assert_admin_success
2930

3031

3132
class TestSuiteInterval(unittest.TestCase):
@@ -38,7 +39,7 @@ def setUpClass(cls):
3839
cls.srv.start()
3940

4041
cls.adm = cls.srv.admin
41-
cls.adm(r"""
42+
resp = cls.adm(r"""
4243
_, datetime = pcall(require, 'datetime')
4344
4445
box.schema.space.create('test')
@@ -59,7 +60,10 @@ def setUpClass(cls):
5960
return arg1 - arg2
6061
end
6162
rawset(_G, 'sub', sub)
63+
64+
return true
6265
""")
66+
assert_admin_success(resp)
6367

6468
cls.con = tarantool.Connection(cls.srv.host, cls.srv.args['primary'],
6569
user='test', password='test')

0 commit comments

Comments
 (0)