Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Mar 28, 2023
1 parent 87f2377 commit 8f1ce0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions aio_pika/channel.py
Expand Up @@ -101,7 +101,10 @@ def is_closed(self) -> bool:
side or after the close() method has been called."""
if not self.is_initialized or self._closed:
return True
return self.channel.is_closed
channel = self._channel
if channel is None:
return True
return channel.channel.is_closed

async def close(
self,
Expand Down Expand Up @@ -161,13 +164,14 @@ async def _open(self) -> None:
channel_number=self._channel_number,
)

self._channel = channel
try:
self._channel = channel
await self._on_open()
self._closed = False
except Exception as e:
except BaseException as e:
await channel.close(e)
self._channel = None
raise
self._closed = False

async def initialize(self, timeout: TimeoutType = None) -> None:
if self.is_initialized:
Expand Down
4 changes: 4 additions & 0 deletions aio_pika/robust_channel.py
Expand Up @@ -89,6 +89,10 @@ async def restore(self) -> None:

async def __close_callback(self, _: Any, exc: BaseException) -> None:
if isinstance(exc, asyncio.CancelledError):
# This happens only if the channel is forced to close from the
# outside, for example, if the connection is closed.
# Of course, here you need to exit fron this function
# as soon as possible and to avoid a recovery attempt.
return

in_restore_state = not self.__restored
Expand Down
5 changes: 5 additions & 0 deletions tests/test_amqp.py
Expand Up @@ -877,6 +877,11 @@ async def test_wrong_credentials(
async def test_set_qos(self, channel: aio_pika.Channel):
await channel.set_qos(prefetch_count=1, global_=True)

async def test_set_qos_deprecated_all_channels(
self, channel: aio_pika.Channel
):
await channel.set_qos(prefetch_count=1, all_channels=True)

async def test_exchange_delete(
self, channel: aio_pika.Channel, declare_exchange,
):
Expand Down

0 comments on commit 8f1ce0c

Please sign in to comment.