Skip to content

Commit

Permalink
Rename internal _transport variable
Browse files Browse the repository at this point in the history
"transport" is a keyword that is used to define SSL connection in
Tarantool Enterprise 2.10 and newer. It would be convenient to use
`self._transport` to store user input `transport` variable, but this
name is already used to store connection transport. This patch renames
the instance variable.

Part of igorcoding#22
  • Loading branch information
DifferentialOrange committed Aug 9, 2022
1 parent 8a8a227 commit a6f8404
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
26 changes: 13 additions & 13 deletions asynctnt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Connection(Api):
'_fetch_schema', '_auto_refetch_schema', '_initial_read_buffer_size',
'_encoding', '_connect_timeout', '_reconnect_timeout',
'_request_timeout', '_ping_timeout', '_loop', '_state', '_state_prev',
'_transport', '_protocol',
'_connection_transport', '_protocol',
'_disconnect_waiter', '_reconnect_task',
'_connect_lock', '_disconnect_lock',
'_ping_task', '__create_task'
Expand Down Expand Up @@ -138,7 +138,7 @@ def __init__(self, *,
self._loop = None
self.__create_task = None

self._transport = None
self._connection_transport = None
self._protocol: Optional[protocol.Protocol] = None

self._state = ConnectionState.DISCONNECTED
Expand All @@ -157,9 +157,9 @@ def _set_state(self, new_state: ConnectionState):
self._state = new_state

def connection_lost(self, exc):
if self._transport:
self._transport.close()
self._transport = None
if self._connection_transport:
self._connection_transport.close()
self._connection_transport = None

if self._disconnect_waiter:
# disconnect() call happened
Expand Down Expand Up @@ -294,7 +294,7 @@ async def full_connect():
logger.info('%s Connected successfully', self.fingerprint)
self._set_state(ConnectionState.CONNECTED)

self._transport = tr
self._connection_transport = tr
self._protocol = pr
self._set_db(self._protocol.get_common_db())
self._reconnect_task = None
Expand Down Expand Up @@ -379,17 +379,17 @@ async def disconnect(self):
self._ping_task = None

self._clear_db()
if self._transport:
if self._connection_transport:
self._disconnect_waiter = _create_future(self._loop)
self._transport.close()
self._transport = None
self._connection_transport.close()
self._connection_transport = None
self._protocol = None

await self._disconnect_waiter
self._disconnect_waiter = None
self._set_state(ConnectionState.DISCONNECTED)
else:
self._transport = None
self._connection_transport = None
self._protocol = None
self._disconnect_waiter = None
self._set_state(ConnectionState.DISCONNECTED)
Expand All @@ -414,10 +414,10 @@ def close(self):
self._ping_task.cancel()
self._ping_task = None

if self._transport:
self._transport.close()
if self._connection_transport:
self._connection_transport.close()

self._transport = None
self._connection_transport = None
self._protocol = None
self._disconnect_waiter = None
self._clear_db()
Expand Down
28 changes: 14 additions & 14 deletions asynctnt/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def __init__(self, tnt, on_exit):
super().__init__()
self._tnt = tnt
self._on_exit = on_exit
self._transport = None
self._connection_transport = None

@property
def logger(self):
return self._tnt.logger

@property
def pid(self):
return self._transport.get_pid() if self._transport else None
return self._connection_transport.get_pid() if self._connection_transport else None

def connection_made(self, transport):
self.logger.info('Process started')
self._transport = transport
self._connection_transport = transport

def pipe_data_received(self, fd, data):
if not data:
Expand All @@ -62,28 +62,28 @@ def pipe_data_received(self, fd, data):
self.logger.info('=> %s', line)

def process_exited(self):
return_code = self._transport.get_returncode()
return_code = self._connection_transport.get_returncode()
if callable(self._on_exit):
self._on_exit(return_code)

@property
def returncode(self):
return self._transport.get_returncode()
return self._connection_transport.get_returncode()

async def wait(self):
"""Wait until the process exit and return the process return code.
This method is a coroutine."""
return await self._transport._wait()
return await self._connection_transport._wait()

def send_signal(self, signal):
self._transport.send_signal(signal)
self._connection_transport.send_signal(signal)

def terminate(self):
self._transport.terminate()
self._connection_transport.terminate()

def kill(self):
self._transport.kill()
self._connection_transport.kill()


class TarantoolInstance(metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -618,7 +618,7 @@ def __init__(self, **kwargs):
self._loop = get_running_loop(kwargs.pop('loop', None))

self._is_stopping = False
self._transport = None
self._connection_transport = None
self._protocol = None
self._last_return_code = None
self._stop_event = asyncio.Event()
Expand Down Expand Up @@ -674,7 +674,7 @@ async def start(self, *, wait=True, recreate=True):
args = [initlua_path]
else:
args = self._command_args
self._transport, self._protocol = await self._loop.subprocess_exec(
self._connection_transport, self._protocol = await self._loop.subprocess_exec(
factory,
self._command_to_run, *args,
stdin=None,
Expand Down Expand Up @@ -739,9 +739,9 @@ def cleanup(self):
self._logger.info('Finished with return code %d', return_code)

self._is_stopping = False
if self._transport:
self._transport.close()
self._transport = None
if self._connection_transport:
self._connection_transport.close()
self._connection_transport = None
self._protocol = None
self._stop_event.clear()

Expand Down
14 changes: 7 additions & 7 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def test__connect(self):
c = await conn.connect()
self.assertEqual(conn.loop, self.loop)
self.assertEqual(c, conn)
self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand All @@ -64,7 +64,7 @@ async def test__connect_direct(self):
self.assertEqual(conn.loop, self.loop)
self.assertIsNone(conn.initial_read_buffer_size)

self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand Down Expand Up @@ -100,7 +100,7 @@ async def test__connect_unix(self):
self.assertEqual(conn.loop, self.loop)
self.assertIsNone(conn.initial_read_buffer_size)

self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand All @@ -119,7 +119,7 @@ async def test__connect_contextmanager(self):
self.assertEqual(conn.state, ConnectionState.DISCONNECTED)

async with conn:
self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand Down Expand Up @@ -163,7 +163,7 @@ async def test__connect_no_schema(self):
fetch_schema=False,
auto_refetch_schema=False)
async with conn:
self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand All @@ -176,7 +176,7 @@ async def test__connect_auth(self):
username='t1', password='t1',
reconnect_timeout=0)
async with conn:
self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand All @@ -193,7 +193,7 @@ async def test__connect_auth_no_schema(self):
self.assertEqual(conn.username, 't1')
self.assertEqual(conn.password, 't1')
async with conn:
self.assertIsNotNone(conn._transport)
self.assertIsNotNone(conn._connection_transport)
self.assertIsNotNone(conn._protocol)
self.assertTrue(conn.is_connected)
self.assertTrue(conn.is_fully_connected)
Expand Down

0 comments on commit a6f8404

Please sign in to comment.