|
21 | 21 | from cassandra import OperationTimedOut |
22 | 22 | from cassandra.cluster import Cluster |
23 | 23 | from cassandra.connection import (Connection, HEADER_DIRECTION_TO_CLIENT, ProtocolError, |
24 | | - locally_supported_compressions, ConnectionHeartbeat, _Frame, Timer, TimerManager, |
| 24 | + locally_supported_compressions, ConnectionHeartbeat, HeartbeatFuture, _Frame, Timer, TimerManager, |
25 | 25 | ConnectionException, ConnectionShutdown, DefaultEndPoint, ShardAwarePortGenerator) |
26 | 26 | from cassandra.marshal import uint8_pack, uint32_pack, int32_pack |
27 | 27 | from cassandra.protocol import (write_stringmultimap, write_int, write_string, |
@@ -463,6 +463,31 @@ def test_no_req_ids(self, *args): |
463 | 463 | holder.return_connection.assert_has_calls( |
464 | 464 | [call(max_connection)] * get_holders.call_count) |
465 | 465 |
|
| 466 | + def test_heartbeat_future_releases_request_id_when_send_fails(self, *args): |
| 467 | + connection = Connection(DefaultEndPoint('1.2.3.4')) |
| 468 | + connection.push = Mock(side_effect=ConnectionException("write failed")) |
| 469 | + owner = Mock() |
| 470 | + initial_in_flight = connection.in_flight |
| 471 | + initial_request_ids = len(connection.request_ids) |
| 472 | + |
| 473 | + # HostConnection.return_connection releases the heartbeat's in-flight slot. |
| 474 | + def return_connection(conn): |
| 475 | + with conn.lock: |
| 476 | + conn.in_flight -= 1 |
| 477 | + |
| 478 | + owner.return_connection.side_effect = return_connection |
| 479 | + |
| 480 | + future = HeartbeatFuture(connection, owner) |
| 481 | + |
| 482 | + with pytest.raises(ConnectionException): |
| 483 | + future.wait(0) |
| 484 | + |
| 485 | + owner.return_connection(connection) |
| 486 | + |
| 487 | + assert connection.in_flight == initial_in_flight |
| 488 | + assert len(connection.request_ids) == initial_request_ids |
| 489 | + assert not connection._requests |
| 490 | + |
466 | 491 | def test_unexpected_response(self, *args): |
467 | 492 | request_id = 999 |
468 | 493 |
|
|
0 commit comments