Skip to content

Fix unittest warnings #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Package build (#238).
- Allow any MessagePack supported type as a request key (#240).
- Puting test files in pip package (#238).
- Make connection close idempotent (#250).

## 0.9.0 - 2022-06-20

Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dbapi-compliance==1.15.0
git+https://github.com/baztian/dbapi-compliance.git@ea7cb1b4#egg=dbapi-compliance
pyyaml==6.0
importlib-metadata >= 1.0 ; python_version < '3.8'
5 changes: 3 additions & 2 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ def __init__(self, host, port,

def close(self):
"""
Close a connection to the server.
Close a connection to the server. The method is idempotent.
"""

self._socket.close()
if self._socket is not None:
self._socket.close()
self._socket = None

def is_closed(self):
Expand Down
7 changes: 6 additions & 1 deletion test/suites/lib/tarantool_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def check_port(port, rais=True):
sock = socket.create_connection(("localhost", port))
except socket.error:
return True
sock.close()

if rais:
raise RuntimeError("The server is already running on port {0}".format(port))
return False
Expand Down Expand Up @@ -136,7 +138,7 @@ def __init__(self,
ssl_ca_file=None,
ssl_ciphers=None,
create_unix_socket=False):
os.popen('ulimit -c unlimited')
os.popen('ulimit -c unlimited').close()

if create_unix_socket:
self.host = None
Expand Down Expand Up @@ -210,6 +212,7 @@ def wait_until_started(self):
while True:
ans = temp('box.info.status')[0]
if ans in ('running', 'hot_standby', 'orphan') or ans.startswith('replica'):
temp.disconnect()
return True
elif ans in ('loading',):
continue
Expand Down Expand Up @@ -262,6 +265,8 @@ def clean(self):
if (self._socket is not None) and (not self._socket.file.closed):
self._socket.close()

del self.log_des

def __del__(self):
self.stop()
self.clean()
Expand Down
83 changes: 48 additions & 35 deletions test/suites/test_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def setUpClass(self):
self.adm("fiber = require('fiber')")
self.adm("uuid = require('uuid')")

if not sys.platform.startswith("win"):
self.sock_srv = TarantoolServer(create_unix_socket=True)
self.sock_srv.script = 'test/suites/box.lua'
self.sock_srv.start()
else:
self.sock_srv = None

def setUp(self):
# prevent a remote tarantool from clean our session
if self.srv.is_started():
Expand Down Expand Up @@ -124,7 +131,7 @@ def test_03_delete(self):
self.assertSequenceEqual(self.con.delete('space_1', [20]), [])
self.assertSequenceEqual(self.con.select('space_1', [20], index='primary'), [])
# Check that <index_id> field has no meaning, yet.
with self.assertRaisesRegexp(tarantool.DatabaseError,
with self.assertRaisesRegex(tarantool.DatabaseError,
'(19, .*)'):
self.con.delete('space_1', [1, 'tuple_21'])
self.assertSequenceEqual(self.con.select('space_1', [21], index='primary'), [[21, 1, 'tuple_21']])
Expand All @@ -134,7 +141,7 @@ def test_04_replace(self):
self.assertSequenceEqual(self.con.replace('space_1', [2, 2, 'tuple_3']), [[2, 2, 'tuple_3']])
self.assertSequenceEqual(self.con.select('space_1', 2), [[2, 2, 'tuple_3']])
# Check replace that isn't Ok.
with self.assertRaisesRegexp(tarantool.DatabaseError,
with self.assertRaisesRegex(tarantool.DatabaseError,
'(39, .*)'):
self.assertSequenceEqual(self.con.replace('space_1', [2, 2]), [[2, 2, 'tuple_2']])

Expand Down Expand Up @@ -164,39 +171,42 @@ def test_06_update(self):

def test_07_call_16(self):
con = tarantool.Connection(self.srv.host, self.srv.args['primary'], call_16 = True)
con.authenticate('test', 'test')
self.assertSequenceEqual(con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode')
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode', '{[1, 2]: "world"}')
ans = con.call('fiber.time')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], float)
ans = con.call('fiber.time64')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], int)
ans = con.call('uuid.str')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], str)
try:
con.authenticate('test', 'test')
self.assertSequenceEqual(con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
with self.assertRaisesRegex(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode')
with self.assertRaisesRegex(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode', '{[1, 2]: "world"}')
ans = con.call('fiber.time')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], float)
ans = con.call('fiber.time64')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], int)
ans = con.call('uuid.str')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], str)

self.assertSequenceEqual(con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', 'fld_1'), [['fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', 'fld_1'), [['fld_1']])
finally:
con.close()

def test_07_call_17(self):
con = tarantool.Connection(self.srv.host, self.srv.args['primary'])
con.authenticate('test', 'test')
self.assertSequenceEqual(con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
with self.assertRaisesRegex(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode')
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
with self.assertRaisesRegex(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode', '{[1, 2]: "world"}')
ans = con.call('fiber.time')
self.assertEqual(len(ans), 1)
Expand Down Expand Up @@ -302,22 +312,25 @@ def test_13_unix_socket_connect(self):
if sys.platform.startswith("win"):
self.skipTest("Skip UNIX socket tests on Windows since it uses remote server")

self.sock_srv = TarantoolServer(create_unix_socket=True)
self.sock_srv.script = 'test/suites/box.lua'
self.sock_srv.start()
sock_con = tarantool.connect(self.sock_srv.host, self.sock_srv.args['primary'])
try:
self.assertEqual(sock_con.ping(notime=True), "Success")
finally:
sock_con.close()

self.sock_con = tarantool.connect(self.sock_srv.host, self.sock_srv.args['primary'])
self.assertEqual(self.sock_con.ping(notime=True), "Success")
def test_14_idempotent_close(self):
con = tarantool.connect(self.srv.host, self.srv.args['primary'])
con.close()
self.assertEqual(con.is_closed(), True)
con.close()
self.assertEqual(con.is_closed(), True)

@classmethod
def tearDownClass(self):
self.con.close()
self.srv.stop()
self.srv.clean()

if hasattr(self, 'sock_srv'):
if self.sock_srv is not None:
self.sock_srv.stop()
self.sock_srv.clean()

if hasattr(self, 'sock_con'):
self.sock_con.close()
Loading