From c7252e4551c2c2645cbb269abd29123722e851f1 Mon Sep 17 00:00:00 2001 From: Yaniv Michael Kaul Date: Fri, 6 Feb 2026 12:28:18 +0200 Subject: [PATCH 1/2] (fix) test: Fix KeyError in test_idle_heartbeat with connection replacement The test_idle_heartbeat test was failing with a KeyError when connections were dynamically replaced during the test run in shard-aware environments. Root cause: The test captures connection object IDs at the start, sleeps for heartbeat intervals, then tries to validate those connections. In shard-aware ScyllaDB deployments, the driver may replace connections during this window. When a connection is replaced, the new connection object has a different Python ID, causing a KeyError on lookup. Fix: Skip validation for connections that weren't present in the initial snapshot. This preserves the test's intent (validating heartbeats on stable connections) while being robust to dynamic connection management in shard-aware mode. I'm not sure this is a great fix. I don't think it has anything to do with this branch. I'll push it and if it's OK, I'll also create a separate PR for it. Why it popped now? Signed-off-by: Yaniv Kaul --- tests/integration/standard/test_cluster.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/integration/standard/test_cluster.py b/tests/integration/standard/test_cluster.py index bf62f5df48..f1e64c9a0a 100644 --- a/tests/integration/standard/test_cluster.py +++ b/tests/integration/standard/test_cluster.py @@ -769,8 +769,14 @@ def test_idle_heartbeat(self): connections = [c for holders in cluster.get_connection_holders() for c in holders.get_connections()] # make sure requests were sent on all connections + # Note: connections can be replaced in shard-aware environments, so we skip + # connections that weren't present in the initial snapshot for c in connections: - expected_ids = connection_request_ids[id(c)] + conn_id = id(c) + if conn_id not in connection_request_ids: + # Connection was replaced during the test, skip validation + continue + expected_ids = connection_request_ids[conn_id] expected_ids.rotate(-1) with c.lock: assertListEqual(list(c.request_ids), list(expected_ids)) From 6cc6e02ea063ce76c3beb8258b2598653693afb1 Mon Sep 17 00:00:00 2001 From: Yaniv Michael Kaul Date: Thu, 26 Mar 2026 09:34:10 +0200 Subject: [PATCH 2/2] fix: keep idle heartbeat test assertions meaningful --- tests/integration/standard/test_cluster.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/standard/test_cluster.py b/tests/integration/standard/test_cluster.py index f1e64c9a0a..4aa15ef4ce 100644 --- a/tests/integration/standard/test_cluster.py +++ b/tests/integration/standard/test_cluster.py @@ -771,6 +771,7 @@ def test_idle_heartbeat(self): # make sure requests were sent on all connections # Note: connections can be replaced in shard-aware environments, so we skip # connections that weren't present in the initial snapshot + validated_connections = 0 for c in connections: conn_id = id(c) if conn_id not in connection_request_ids: @@ -780,6 +781,9 @@ def test_idle_heartbeat(self): expected_ids.rotate(-1) with c.lock: assertListEqual(list(c.request_ids), list(expected_ids)) + validated_connections += 1 + + assert validated_connections > 0 # assert idle status assert all(c.is_idle for c in connections)