-
Notifications
You must be signed in to change notification settings - Fork 190
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
fix: raise ChannelInvalidStateError at exchange.publish with closed channel #637
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,34 @@ async def test_simple_publish_and_receive_to_bound_exchange( | |
|
||
await queue.unbind(dest_exchange, routing_key) | ||
|
||
async def test_simple_publish_with_closed_channel( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be called "test_simple_publish_with_closed_connection" ? |
||
self, | ||
connection: aio_pika.Connection, | ||
declare_exchange: Callable, | ||
declare_queue: Callable, | ||
): | ||
routing_key = get_random_name() | ||
|
||
channel = await connection.channel(publisher_confirms=False) | ||
|
||
exchange = await declare_exchange( | ||
"direct", auto_delete=True, channel=channel, | ||
) | ||
|
||
await connection.close() | ||
|
||
body = bytes(shortuuid.uuid(), "utf-8") | ||
|
||
with pytest.raises(aiormq.exceptions.ChannelInvalidStateError): | ||
await exchange.publish( | ||
Message( | ||
body, | ||
content_type="text/plain", | ||
headers={"foo": "bar"}, | ||
), | ||
routing_key, | ||
) | ||
|
||
async def test_incoming_message_info( | ||
self, | ||
channel: aio_pika.Channel, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't channel closure checked in this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it is waiting for channel readiness forewer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean waiting here?
aio-pika/aio_pika/robust_channel.py
Lines 78 to 80 in 9c1ee8f
There is waiting for connection readiness - not for channel readiness, and in the test you are closing connection, not channel. Maybe in
publish
method should be checked connection (not channel) andaiormq.exceptions.ConnectionClosed
exception raised?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, that is correct. I just followed the aiormq exceptions style. Also, connection and channel and quite closely related, so they can be open/closed both only. I am checking channel due it is the most important thing for we functionality. Can @mosquito resolve the dispute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the code without any problems and basically agree with your points, but not sure about the person, who makes the final decision about PR merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, we have no access to
self.channel._connection
object due it isRobustChannel
-class attribute only. So, we should checkself.channel
to be compatible with anyAbstractChannel
implementation