|
21 | 21 | from cassandra import ConsistencyLevel, 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 | ConnectionBusy, ConnectionException, ConnectionShutdown, DefaultEndPoint, |
26 | 26 | ShardAwarePortGenerator) |
27 | 27 | from cassandra.marshal import uint8_pack, uint32_pack, int32_pack |
@@ -510,6 +510,21 @@ def test_no_req_ids(self, *args): |
510 | 510 | holder.return_connection.assert_has_calls( |
511 | 511 | [call(max_connection)] * get_holders.call_count) |
512 | 512 |
|
| 513 | + def test_heartbeat_future_releases_request_id_when_send_fails(self, *args): |
| 514 | + connection = Connection(DefaultEndPoint('1.2.3.4')) |
| 515 | + connection.push = Mock(side_effect=ConnectionException("write failed")) |
| 516 | + initial_in_flight = connection.in_flight |
| 517 | + initial_request_ids = len(connection.request_ids) |
| 518 | + |
| 519 | + future = HeartbeatFuture(connection, Mock()) |
| 520 | + |
| 521 | + with pytest.raises(ConnectionException): |
| 522 | + future.wait(0) |
| 523 | + |
| 524 | + assert connection.in_flight == initial_in_flight |
| 525 | + assert len(connection.request_ids) == initial_request_ids |
| 526 | + assert not connection._requests |
| 527 | + |
513 | 528 | def test_unexpected_response(self, *args): |
514 | 529 | request_id = 999 |
515 | 530 |
|
|
0 commit comments