-
Notifications
You must be signed in to change notification settings - Fork 30
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/update_indexer_cookie_policy #308
Conversation
… returning any cookie
WalkthroughThe update primarily refines the handling of cookies within network communication, accommodating scenarios where cookies are not used by the Indexer exchange server but are required by the chain server. It introduces checks and error handling for cookie-related operations, ensuring robustness in network metadata management. Additionally, the removal of Changes
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #308 +/- ##
==========================================
+ Coverage 73.06% 74.92% +1.85%
==========================================
Files 48 48
Lines 3416 3422 +6
Branches 304 306 +2
==========================================
+ Hits 2496 2564 +68
+ Misses 839 772 -67
- Partials 81 86 +5 ☔ View full report in Codecov by Sentry. |
pyinjective/core/network.py
Outdated
expiration_time = 0 | ||
else: | ||
expiration_time = datetime.datetime.strptime( | ||
cookie["GCLB"]["expires"], "%a, %d-%b-%Y %H:%M:%S %Z" |
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.
Is there any chance "GCLB" key is present, but "expires" sub-key is not?
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 in the examples I checked. If that happens the expiration check should fail, since that would be unexpected.
There is no way to test it correctly now because there are no k8s servers supported
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
pyproject.toml
is excluded by:!**/*.toml
Files selected for processing (3)
- CHANGELOG.md (1 hunks)
- pyinjective/core/network.py (4 hunks)
- tests/core/test_network.py (1 hunks)
Additional comments: 14
tests/core/test_network.py (8)
- 6-18: The test
test_chain_metadata
in theTestBareMetalLoadBalancedCookieAssistant
class correctly simulates the scenario where a cookie is present in the server response and asserts that the metadata is correctly formed. This test is well-structured and follows best practices for asynchronous testing with pytest.- 20-29: The test
test_chain_metadata_fails_when_cookie_info_not_included_in_server_response
in theTestBareMetalLoadBalancedCookieAssistant
class effectively simulates a failure scenario where the server response does not include cookie information. The use ofpytest.raises
to expect aRuntimeError
is appropriate and correctly implemented.- 31-42: The test
test_exchange_metadata
in theTestBareMetalLoadBalancedCookieAssistant
class correctly simulates the scenario where a cookie is present in the server response for exchange metadata. The test is well-structured, and the assertion validates the expected behavior correctly.- 44-54: The test
test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response
in theTestBareMetalLoadBalancedCookieAssistant
class effectively tests the scenario where no cookie information is included in the server response for exchange metadata. The assertion thatmetadata
isNone
is correct and aligns with the expected behavior.- 57-69: The test
test_chain_metadata
in theTestKubernetesLoadBalancedCookieAssistant
class correctly simulates the scenario where a cookie is present in the server response and asserts that the metadata is correctly formed. This test mirrors the structure and logic of the corresponding test in theTestBareMetalLoadBalancedCookieAssistant
class, maintaining consistency across tests.- 71-80: The test
test_chain_metadata_fails_when_cookie_info_not_included_in_server_response
in theTestKubernetesLoadBalancedCookieAssistant
class effectively simulates a failure scenario where the server response does not include cookie information. The use ofpytest.raises
to expect aRuntimeError
is appropriate and correctly implemented, mirroring the structure of the corresponding test in theTestBareMetalLoadBalancedCookieAssistant
class.- 82-93: The test
test_exchange_metadata
in theTestKubernetesLoadBalancedCookieAssistant
class correctly simulates the scenario where a cookie is present in the server response for exchange metadata. The test is well-structured, and the assertion validates the expected behavior correctly, mirroring the structure of the corresponding test in theTestBareMetalLoadBalancedCookieAssistant
class.- 95-105: The test
test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response
in theTestKubernetesLoadBalancedCookieAssistant
class effectively tests the scenario where no cookie information is included in the server response for exchange metadata. The assertion thatmetadata
isNone
is correct and aligns with the expected behavior, mirroring the structure of the corresponding test in theTestBareMetalLoadBalancedCookieAssistant
class.CHANGELOG.md (2)
- 5-9: The changelog entry for version 1.3.1 clearly outlines the changes made to the cookie assistant logic to accommodate the different cookie policies of the Indexer exchange server and the chain server. This entry is concise and informative, providing a clear summary of the changes and their impact.
- 9-9: The changelog entry for version 1.3.0 mentions the removal of
asyncio
from the dependencies. This entry is clear and concise, accurately reflecting a significant change that could affect users and developers working with the software.pyinjective/core/network.py (4)
- 26-29: The modification in the
exchange_metadata
method to returnNone
when the cookie is eitherNone
or an empty string is a logical and clean way to handle scenarios where cookies are not applicable. This change ensures that the method's behavior is consistent with the expected functionality in environments where cookies are not used.- 73-73: Setting
cookie_info
to an empty string when no cookie is present in the_fetch_exchange_cookie
method of theKubernetesLoadBalancedCookieAssistant
class is a sensible default. This change prevents potentialNoneType
errors in subsequent operations involvingcookie_info
.- 89-94: The addition of a check for the "GCLB" key in the cookie before accessing its expiration time in the
_is_cookie_expired
method enhances the robustness of the cookie expiration logic. This change ensures that the method only operates on valid cookie data, preventing potentialKeyError
exceptions.- 141-141: Similar to the KubernetesLoadBalancedCookieAssistant class, setting
cookie_info
to an empty string when no cookie is present in the_fetch_exchange_cookie
method of theBareMetalLoadBalancedCookieAssistant
class is a prudent choice. This ensures consistency in handling cookie information across different assistant classes.
…s assistant to tackle the suggestion in the PR review
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- pyinjective/core/network.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- pyinjective/core/network.py
Summary by CodeRabbit
New Features
Bug Fixes
Tests