Copilot commented on code in PR #1256:
URL: 
https://github.com/apache/cassandra-python-driver/pull/1256#discussion_r2620636887


##########
tests/unit/test_response_future.py:
##########
@@ -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

Review Comment:
   Corrected spelling of 'poilcy' to 'policy'.
   ```suggestion
           # if the return value from add_failure() on the conviction policy is 
false so we can
   ```



##########
tests/unit/test_response_future.py:
##########
@@ -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

Review Comment:
   The function name 'foo' is not descriptive. Consider renaming it to 
something more meaningful like 'signal_failure_wrapper' or 
'delegate_signal_connection_failure' to clarify its purpose of delegating to 
the actual Cluster implementation.
   ```suggestion
           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
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to