-
Notifications
You must be signed in to change notification settings - Fork 567
PYTHON-539 Timeouts in ResponseFuture should notify the conviction policy #1256
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
Open
absurdfarce
wants to merge
2
commits into
apache:master
Choose a base branch
from
absurdfarce:python-539
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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 hidden or 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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,17 +19,17 @@ | |||||||||||||
| from mock import Mock, MagicMock, ANY | ||||||||||||||
|
|
||||||||||||||
| from cassandra import ConsistencyLevel, Unavailable, SchemaTargetType, SchemaChangeType, OperationTimedOut | ||||||||||||||
| from cassandra.cluster import Session, ResponseFuture, NoHostAvailable, ProtocolVersion | ||||||||||||||
| from cassandra.connection import Connection, ConnectionException | ||||||||||||||
| from cassandra.cluster import Session, ResponseFuture, NoHostAvailable, ProtocolVersion, Cluster | ||||||||||||||
| from cassandra.connection import Connection, ConnectionException, DefaultEndPoint | ||||||||||||||
| from cassandra.protocol import (ReadTimeoutErrorMessage, WriteTimeoutErrorMessage, | ||||||||||||||
| UnavailableErrorMessage, ResultMessage, QueryMessage, | ||||||||||||||
| OverloadedErrorMessage, IsBootstrappingErrorMessage, | ||||||||||||||
| PreparedQueryNotFound, PrepareMessage, | ||||||||||||||
| RESULT_KIND_ROWS, RESULT_KIND_SET_KEYSPACE, | ||||||||||||||
| RESULT_KIND_SCHEMA_CHANGE, RESULT_KIND_PREPARED, | ||||||||||||||
| ProtocolHandler) | ||||||||||||||
| from cassandra.policies import RetryPolicy | ||||||||||||||
| from cassandra.pool import NoConnectionsAvailable | ||||||||||||||
| from cassandra.policies import RetryPolicy, ConvictionPolicy | ||||||||||||||
| from cassandra.pool import NoConnectionsAvailable, Host | ||||||||||||||
| from cassandra.query import SimpleStatement | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
@@ -160,6 +160,49 @@ def test_heartbeat_defunct_deadlock(self): | |||||||||||||
| rf._on_timeout() | ||||||||||||||
| self.assertRaisesRegexp(OperationTimedOut, "Connection defunct by heartbeat", rf.result) | ||||||||||||||
|
|
||||||||||||||
| def test_timeout_updates_conviction_policy(self): | ||||||||||||||
| """ | ||||||||||||||
| PYTHON-539 | ||||||||||||||
|
|
||||||||||||||
| Timeouts from ResponseFuture should notify the host's conviction policy, giving | ||||||||||||||
| the driver a mechanism to take action on repeated/systemic timeouts. | ||||||||||||||
| """ | ||||||||||||||
| conviction_policy = MagicMock(spec=ConvictionPolicy) | ||||||||||||||
| conviction_policy.add_failure.return_value = False | ||||||||||||||
|
|
||||||||||||||
| host = Host(DefaultEndPoint("ip1"), lambda h: conviction_policy) | ||||||||||||||
|
|
||||||||||||||
| connection = MagicMock(spec=Connection) | ||||||||||||||
| connection._requests = {1:False} | ||||||||||||||
| connection.orphaned_request_ids = set() | ||||||||||||||
| connection.orphaned_threshold = 2 | ||||||||||||||
|
|
||||||||||||||
| pool = Mock() | ||||||||||||||
| pool.is_shutdown = False | ||||||||||||||
| pool.borrow_connection.return_value = [connection, 1] | ||||||||||||||
|
|
||||||||||||||
| session = self.make_basic_session() | ||||||||||||||
| session.cluster._default_load_balancing_policy.make_query_plan.return_value = [host] | ||||||||||||||
| session._pools.get.return_value = pool | ||||||||||||||
|
|
||||||||||||||
| # An extra bit of connective tissue. session.cluster is a mock but we want to use the | ||||||||||||||
| # actual impl in Cluster in order to get into the host (and from there to the conviction | ||||||||||||||
| # policy). As of this writing Cluster.signal_connection_failure is effectively static | ||||||||||||||
| # if the return value from add_failure() on the conviction poilcy is false so we can | ||||||||||||||
| # create this linkage _using the actual impl in Cluster_ via a mock side_effect. | ||||||||||||||
| def foo(*args, **kwargs): | ||||||||||||||
| Cluster.signal_connection_failure(Cluster(), *args, **kwargs) | ||||||||||||||
| session.cluster.signal_connection_failure.side_effect = foo | ||||||||||||||
|
Comment on lines
+193
to
+195
|
||||||||||||||
| def foo(*args, **kwargs): | |
| Cluster.signal_connection_failure(Cluster(), *args, **kwargs) | |
| session.cluster.signal_connection_failure.side_effect = foo | |
| def delegate_signal_connection_failure(*args, **kwargs): | |
| Cluster.signal_connection_failure(Cluster(), *args, **kwargs) | |
| session.cluster.signal_connection_failure.side_effect = delegate_signal_connection_failure |
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.
Corrected spelling of 'poilcy' to 'policy'.