Skip to content

Commit 2784e3f

Browse files
tests/integration/standard: fix test to reflect RR policy randomizing starting point
The `test_profile_lb_swap` test logic assumed that `populate` was called before control connection (cc) was created, meaning only the contact points from the cluster configuration were known (a single host). Due to that the starting point was not random. This commit updates the test to reflect the new behavior, where `populate` is called on the load-balancing policy after the control connection is created. This allows the policy to be updated with all known hosts and ensures the starting point is properly randomized.
1 parent 12fdb74 commit 2784e3f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

tests/integration/standard/test_cluster.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,9 @@ def test_profile_lb_swap(self):
900900
"""
901901
Tests that profile load balancing policies are not shared
902902
903-
Creates two LBP, runs a few queries, and validates that each LBP is execised
904-
seperately between EP's
903+
Creates two LBP, runs a few queries, and validates that each LBP is exercised
904+
separately between EP's. Each RoundRobinPolicy starts from its own random
905+
position and maintains independent round-robin ordering.
905906
906907
@since 3.5
907908
@jira_ticket PYTHON-569
@@ -916,17 +917,28 @@ def test_profile_lb_swap(self):
916917
with TestCluster(execution_profiles=exec_profiles) as cluster:
917918
session = cluster.connect(wait_for_all_pools=True)
918919

919-
# default is DCA RR for all hosts
920920
expected_hosts = set(cluster.metadata.all_hosts())
921-
rr1_queried_hosts = set()
922-
rr2_queried_hosts = set()
923-
924-
rs = session.execute(query, execution_profile='rr1')
925-
rr1_queried_hosts.add(rs.response_future._current_host)
926-
rs = session.execute(query, execution_profile='rr2')
927-
rr2_queried_hosts.add(rs.response_future._current_host)
928-
929-
assert rr2_queried_hosts == rr1_queried_hosts
921+
num_hosts = len(expected_hosts)
922+
assert num_hosts > 1, "Need at least 2 hosts for this test"
923+
924+
rr1_queried_hosts = []
925+
rr2_queried_hosts = []
926+
927+
for _ in range(num_hosts * 2):
928+
rs = session.execute(query, execution_profile='rr1')
929+
rr1_queried_hosts.append(rs.response_future._current_host)
930+
rs = session.execute(query, execution_profile='rr2')
931+
rr2_queried_hosts.append(rs.response_future._current_host)
932+
933+
# Both policies should have queried all hosts
934+
assert set(rr1_queried_hosts) == expected_hosts
935+
assert set(rr2_queried_hosts) == expected_hosts
936+
937+
# The order of hosts should demonstrate round-robin behavior
938+
# After num_hosts queries, the pattern should repeat
939+
for i in range(num_hosts):
940+
assert rr1_queried_hosts[i] == rr1_queried_hosts[i + num_hosts]
941+
assert rr2_queried_hosts[i] == rr2_queried_hosts[i + num_hosts]
930942

931943
def test_ta_lbp(self):
932944
"""

0 commit comments

Comments
 (0)