-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add Unit test for AMQP Client Link with max message size = 0 #43582
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from azure.eventhub._pyamqp.link import Link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from azure.eventhub._pyamqp.receiver import ReceiverLink | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from azure.eventhub._pyamqp.constants import LinkState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from azure.eventhub._pyamqp.link import Source, Target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from unittest.mock import Mock, patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from azure.eventhub._pyamqp.constants import LINK_MAX_MESSAGE_SIZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,6 +87,73 @@ def test_receive_transfer_frame_multiple(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link._incoming_transfer(transfer_frame_two) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert link.current_link_credit == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_max_message_size_negotiation_with_client_unlimited(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Test AMQP attach frame negotiation where client sends max_message_size=0 (unlimited) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and server responds with its limit (20MB), resulting in final size of 20MB. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_session = Mock() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_connection = Mock() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_session._connection = mock_connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SERVER_MAX_MESSAGE_SIZE = 20 * 1024 * 1024 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link = Link( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mock_session, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="test_link", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role=False, # Sender role | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_address="test_source", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_address="test_target", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network_trace=False, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network_trace_params={}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_message_size=LINK_MAX_MESSAGE_SIZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verifying that client sends 0 (unlimited) in attach frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert link.max_message_size == 0, f"Expected client max_message_size=0, got {link._max_message_size}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert link.max_message_size == 0, f"Expected client max_message_size=0, got {link._max_message_size}" | |
| assert link.max_message_size == 0, f"Expected client max_message_size=0, got {link.max_message_size}" |
Copilot
AI
Oct 22, 2025
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.
The mock attach frame list lacks comments explaining what each positional element represents. Add inline comments describing each field (e.g., name, handle, role, snd_settle_mode, rcv_settle_mode, source, target, unsettled, incomplete_unsettled, initial_delivery_count, max_message_size, offered_capabilities, desired_capabilities, properties) to improve test readability and maintainability.
| "test_link", | |
| 3, | |
| False, | |
| 0, | |
| 1, | |
| Source(address="test_source"), | |
| Target(address="test_target"), | |
| None, | |
| False, | |
| None, | |
| 20 * 1024 * 1024, | |
| None, | |
| None, | |
| None, ] | |
| "test_link", # name | |
| 3, # handle | |
| False, # role (False = sender, True = receiver) | |
| 0, # snd_settle_mode | |
| 1, # rcv_settle_mode | |
| Source(address="test_source"),# source | |
| Target(address="test_target"),# target | |
| None, # unsettled | |
| False, # incomplete_unsettled | |
| None, # initial_delivery_count | |
| 20 * 1024 * 1024, # max_message_size | |
| None, # offered_capabilities | |
| None, # desired_capabilities | |
| None, # properties | |
| ] |
Copilot
AI
Oct 22, 2025
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.
There are multiple spaces before the closing bracket. This appears to be inconsistent whitespace that should be removed for cleaner formatting.
| None, ] | |
| None, ] |
Copilot
AI
Oct 22, 2025
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.
The assertion message uses SERVER_MAX_MESSAGE_SIZE directly instead of the expected_final_size variable that was just defined. For consistency and clarity, the message should reference expected_final_size to match what's being tested.
| f"Expected remote_max_message_size={SERVER_MAX_MESSAGE_SIZE}, got {link.remote_max_message_size}" | |
| f"Expected remote_max_message_size={expected_final_size}, got {link.remote_max_message_size}" |
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.
The docstring has trailing whitespace on line 94 and an unnecessary blank line 95. Remove the trailing whitespace and the blank line before the closing triple quotes.