Skip to content

Commit d5f9d37

Browse files
mykauldkropachev
authored andcommitted
(fix) cluster: handle None control_connection_timeout in wait_for_schema_agreement
min(self._timeout, total_timeout - elapsed) raises TypeError when control_connection_timeout is set to None, which is explicitly documented as a supported value (meaning no timeout). Guard the min() call so that when self._timeout is None, we use only the remaining schema agreement wait time.
1 parent 44cf752 commit d5f9d37

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cassandra/cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,8 @@ def wait_for_schema_agreement(self, connection=None, preloaded_results=None, wai
41174117
local_query = QueryMessage(query=maybe_add_timeout_to_query(self._SELECT_SCHEMA_LOCAL, self._metadata_request_timeout),
41184118
consistency_level=cl)
41194119
try:
4120-
timeout = min(self._timeout, total_timeout - elapsed)
4120+
remaining = total_timeout - elapsed
4121+
timeout = min(self._timeout, remaining) if self._timeout is not None else remaining
41214122
peers_result, local_result = connection.wait_for_responses(
41224123
peers_query, local_query, timeout=timeout)
41234124
except OperationTimedOut as timeout:

tests/unit/test_control_connection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ def test_wait_for_schema_agreement_rpc_lookup(self):
287287
assert not self.control_connection.wait_for_schema_agreement()
288288
assert self.time.clock >= self.cluster.max_schema_agreement_wait
289289

290+
291+
def test_wait_for_schema_agreement_none_timeout(self):
292+
"""
293+
When control_connection_timeout is None, wait_for_schema_agreement
294+
should not raise a TypeError on the min() call.
295+
"""
296+
cc = ControlConnection(self.cluster, timeout=None,
297+
schema_event_refresh_window=0,
298+
topology_event_refresh_window=0,
299+
status_event_refresh_window=0)
300+
cc._connection = self.connection
301+
cc._time = self.time
302+
assert cc.wait_for_schema_agreement()
303+
290304
def test_refresh_nodes_and_tokens(self):
291305
self.control_connection.refresh_node_list_and_token_map()
292306
meta = self.cluster.metadata

0 commit comments

Comments
 (0)