Skip to content

Commit a400294

Browse files
api: make connection close idempotent
After this patch, it is possible to call `conn.close()` method multiple times. Part of #250
1 parent 708902e commit a400294

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
149149
- Package build (#238).
150150
- Allow any MessagePack supported type as a request key (#240).
151151
- Puting test files in pip package (#238).
152+
- Make connection close idempotent (#250).
152153

153154
## 0.9.0 - 2022-06-20
154155

Diff for: tarantool/connection.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,11 @@ def __init__(self, host, port,
520520

521521
def close(self):
522522
"""
523-
Close a connection to the server.
523+
Close a connection to the server. The method is idempotent.
524524
"""
525525

526-
self._socket.close()
526+
if self._socket is not None:
527+
self._socket.close()
527528
self._socket = None
528529

529530
def is_closed(self):

Diff for: test/suites/test_dml.py

+7
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ def test_13_unix_socket_connect(self):
309309
self.sock_con = tarantool.connect(self.sock_srv.host, self.sock_srv.args['primary'])
310310
self.assertEqual(self.sock_con.ping(notime=True), "Success")
311311

312+
def test_14_idempotent_close(self):
313+
con = tarantool.connect(self.srv.host, self.srv.args['primary'])
314+
con.close()
315+
self.assertEqual(con.is_closed(), True)
316+
con.close()
317+
self.assertEqual(con.is_closed(), True)
318+
312319
@classmethod
313320
def tearDownClass(self):
314321
self.con.close()

0 commit comments

Comments
 (0)