Skip to content

Commit

Permalink
fix: RobustChannel should not reopen after close() call
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Dec 11, 2024
1 parent 1a8d5b6 commit 181aec8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aio_pika/robust_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ async def _on_close(

return exc

async def close(
self,
exc: Optional[aiormq.abc.ExceptionType] = None,
) -> None:
# Avoid recovery when channel is explicitely closed using this method
self.__restored.clear()
await super().close(exc)

async def reopen(self) -> None:
await super().reopen()
await self.reopen_callbacks()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_amqp_robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,25 @@ async def test_channel_is_ready_after_close_and_reopen(self, connection):
channel: RobustChannel = await connection.channel() # type: ignore
await channel.ready()
await channel.close()
assert channel.is_closed is True

await channel.reopen()
await asyncio.wait_for(channel.ready(), timeout=1)

assert channel.is_closed is False

async def test_channel_can_be_closed(self, connection):
channel: RobustChannel = await connection.channel() # type: ignore
await channel.ready()
await channel.close()

assert channel.is_closed

with pytest.raises(asyncio.TimeoutError):
await asyncio.wait_for(channel.ready(), timeout=1)

assert channel.is_closed


class TestCaseAmqpNoConfirmsRobust(TestCaseAmqpNoConfirms):
pass
Expand Down

0 comments on commit 181aec8

Please sign in to comment.