Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None,
else:
log.debug("Using unnamed external cluster")
if set_keyspace and start:
setup_keyspace(ipformat=ipformat, wait=False)
setup_keyspace(ipformat=ipformat)
return

if is_current_cluster(cluster_name, nodes, workloads):
Expand Down Expand Up @@ -600,7 +600,7 @@ def execute_with_long_wait_retry(session, query, timeout=30):
del tb
tries += 1

raise RuntimeError("Failed to execute query after 100 attempts: {0}".format(query))
raise RuntimeError("Failed to execute query after 10 attempts: {0}".format(query))


def execute_with_retry_tolerant(session, query, retry_exceptions, escape_exception):
Expand Down Expand Up @@ -632,11 +632,7 @@ def drop_keyspace_shutdown_cluster(keyspace_name, session, cluster):
cluster.shutdown()


def setup_keyspace(ipformat=None, wait=True, protocol_version=None, port=9042):
# wait for nodes to startup
if wait:
time.sleep(10)

def setup_keyspace(ipformat=None, protocol_version=None, port=9042):
if protocol_version:
_protocol_version = protocol_version
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def cleanup_clusters():

if not os.environ.get('DISABLE_CLUSTER_CLEANUP'):
for cluster_name in [CLUSTER_NAME, SINGLE_NODE_CLUSTER_NAME, MULTIDC_CLUSTER_NAME,
'shared_aware', 'sni_proxy', 'test_ip_change']:
'cluster_tests', 'shared_aware', 'sni_proxy', 'test_ip_change', 'test_client_routes_replacement']:
try:
cluster = CCMClusterFactory.load(ccm_path, cluster_name)
logging.debug("Using external CCM cluster {0}".format(cluster.name))
Expand Down
13 changes: 12 additions & 1 deletion tests/integration/long/test_loadbalancingpolicies.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
class LoadBalancingPolicyTests(unittest.TestCase):

def setUp(self):
remove_cluster() # clear ahead of test so it doesn't use one left in unknown state
self.coordinator_stats = CoordinatorStats()
self.prepared = None
self.probe_cluster = None
Expand Down Expand Up @@ -191,6 +190,7 @@ def test_token_aware_is_used_by_default(self):
assert isinstance(cluster.profile_manager.default.load_balancing_policy, DCAwareRoundRobinPolicy)

def test_roundrobin(self):
remove_cluster()
use_singledc()
keyspace = 'test_roundrobin'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
Expand Down Expand Up @@ -228,6 +228,7 @@ def test_roundrobin(self):
self.coordinator_stats.assert_query_count_equals(3, 6)

def test_roundrobin_two_dcs(self):
remove_cluster()
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
Expand Down Expand Up @@ -261,6 +262,7 @@ def test_roundrobin_two_dcs(self):
self.coordinator_stats.assert_query_count_equals(5, 3)

def test_roundrobin_two_dcs_2(self):
remove_cluster()
use_multidc([2, 2])
keyspace = 'test_roundrobin_two_dcs_2'
cluster, session = self._cluster_session_with_lbp(RoundRobinPolicy())
Expand Down Expand Up @@ -294,6 +296,7 @@ def test_roundrobin_two_dcs_2(self):
self.coordinator_stats.assert_query_count_equals(5, 3)

def test_dc_aware_roundrobin_two_dcs(self):
remove_cluster()
use_multidc([3, 2])
keyspace = 'test_dc_aware_roundrobin_two_dcs'
cluster, session = self._cluster_session_with_lbp(DCAwareRoundRobinPolicy('dc1'))
Expand All @@ -311,6 +314,7 @@ def test_dc_aware_roundrobin_two_dcs(self):
self.coordinator_stats.assert_query_count_equals(5, 0)

def test_dc_aware_roundrobin_two_dcs_2(self):
remove_cluster()
use_multidc([3, 2])
keyspace = 'test_dc_aware_roundrobin_two_dcs_2'
cluster, session = self._cluster_session_with_lbp(DCAwareRoundRobinPolicy('dc2'))
Expand All @@ -328,6 +332,7 @@ def test_dc_aware_roundrobin_two_dcs_2(self):
self.coordinator_stats.assert_query_count_equals(5, 6)

def test_dc_aware_roundrobin_one_remote_host(self):
remove_cluster()
use_multidc([2, 2])
keyspace = 'test_dc_aware_roundrobin_one_remote_host'
cluster, session = self._cluster_session_with_lbp(DCAwareRoundRobinPolicy('dc2', used_hosts_per_remote_dc=1))
Expand Down Expand Up @@ -410,6 +415,7 @@ def test_token_aware_prepared(self):
self.token_aware(keyspace, True)

def token_aware(self, keyspace, use_prepared=False):
remove_cluster()
use_singledc()
cluster, session = self._cluster_session_with_lbp(TokenAwarePolicy(RoundRobinPolicy()))
self.addCleanup(cluster.shutdown)
Expand Down Expand Up @@ -505,6 +511,7 @@ def test_token_aware_composite_key(self):
assert results[0].i

def test_token_aware_with_rf_2(self, use_prepared=False):
remove_cluster()
use_singledc()
keyspace = 'test_token_aware_with_rf_2'
cluster, session = self._cluster_session_with_lbp(TokenAwarePolicy(RoundRobinPolicy()))
Expand Down Expand Up @@ -617,6 +624,7 @@ def test_token_aware_with_transient_replication(self):

@test_category policy
"""
remove_cluster()
# We can test this with a single dc when CASSANDRA-15670 is fixed
use_multidc([3, 3])

Expand Down Expand Up @@ -647,6 +655,7 @@ def test_token_aware_with_transient_replication(self):


def _set_up_shuffle_test(self, keyspace, replication_factor):
remove_cluster()
use_singledc()
cluster, session = self._cluster_session_with_lbp(
TokenAwarePolicy(RoundRobinPolicy(), shuffle_replicas=True)
Expand Down Expand Up @@ -678,6 +687,7 @@ def _check_query_order_changes(self, session, keyspace):
self.coordinator_stats.reset_counts()

def test_white_list(self):
remove_cluster()
use_singledc()
keyspace = 'test_white_list'

Expand Down Expand Up @@ -723,6 +733,7 @@ def test_black_list_with_host_filter_policy(self):

@test_category policy
"""
remove_cluster()
use_singledc()
keyspace = 'test_black_list_with_hfp'
ignored_address = (IP_FORMAT % 2)
Expand Down
14 changes: 8 additions & 6 deletions tests/integration/simulacron/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from cassandra.policies import HostStateListener, RoundRobinPolicy, WhiteListRoundRobinPolicy

from tests import connection_class, thread_pool_executor_class
from tests.util import late
from tests.util import late, wait_until_not_raised
from tests.integration import requiressimulacron, libevtest
from tests.integration.util import assert_quiescent_pool_state
# important to import the patch PROTOCOL_VERSION from the simulacron module
Expand Down Expand Up @@ -356,13 +356,15 @@ def test_retry_after_defunct(self):
for _ in range(10):
session.execute(query_to_prime)

# Might take some time to close the previous connections and reconnect
time.sleep(10)
assert_quiescent_pool_state(cluster)
# Wait for previous connections to close and pool to stabilize
wait_until_not_raised(
lambda: assert_quiescent_pool_state(cluster),
delay=1, max_attempts=30)
clear_queries()

time.sleep(10)
assert_quiescent_pool_state(cluster)
wait_until_not_raised(
lambda: assert_quiescent_pool_state(cluster),
delay=1, max_attempts=30)

def test_idle_connection_is_not_closed(self):
"""
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/simulacron/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ def start_simulacron():

SERVER_SIMULACRON.start()

# TODO improve this sleep, maybe check the logs like ccm
time.sleep(5)
# Poll the admin endpoint until simulacron is ready
def _check_simulacron_ready():
opener = build_opener(HTTPHandler)
request = Request("http://127.0.0.1:8187/cluster")
opener.open(request, timeout=2)

wait_until_not_raised(_check_simulacron_ready, delay=0.5, max_attempts=30)


def stop_simulacron():
Expand Down
56 changes: 55 additions & 1 deletion tests/integration/standard/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
import pytest
import logging

# Cluster topology groups for test ordering.
# Tests are sorted so that modules sharing the same CCM cluster run
# together, minimising expensive cluster teardown/restart cycles.
# Lower number = runs first. Modules not listed get a high default.
_MODULE_CLUSTER_ORDER = {
# Group 0: default 3-node singledc (CLUSTER_NAME = 'test_cluster')
"test_metadata": 0,
"test_policies": 0,
"test_control_connection": 0,
"test_routing": 0,
"test_prepared_statements": 0,
"test_metrics": 0,
"test_connection": 0,
"test_concurrent": 0,
"test_custom_payload": 0,
"test_query_paging": 0,
"test_single_interface": 0,
# Group 1: 'cluster_tests' (--smp 2, 3 nodes)
"test_cluster": 1,
"test_shard_aware": 1,
# Group 2: 'shared_aware' (--smp 2 --memory 2048M, 3 nodes)
"test_use_keyspace": 2,
"test_client_routes": 2,
# Group 3: single-node cluster
"test_types": 3,
"test_cython_protocol_handlers": 3,
"test_custom_protocol_handler": 3,
"test_row_factories": 3,
"test_udts": 3,
"test_client_warnings": 3,
# Group 4: destructive / special clusters (run last)
"test_ip_change": 4,
"test_authentication": 4,
"test_custom_cluster": 4,
"test_query": 4,
}


def pytest_collection_modifyitems(items):
"""Sort tests so modules with the same cluster topology are adjacent.

Uses the original collection index as tie-breaker so that the
definition order inside each file is preserved (important for tests
that depend on running order, e.g. destructive tablet tests).
"""
orig_order = {id(item): idx for idx, item in enumerate(items)}

def _sort_key(item):
module_name = item.module.__name__.rsplit(".", 1)[-1]
return (_MODULE_CLUSTER_ORDER.get(module_name, 99), item.fspath, orig_order[id(item)])

items[:] = sorted(items, key=_sort_key)


# from https://github.com/streamlit/streamlit/pull/5047/files
def pytest_sessionfinish():
# We're not waiting for scriptrunner threads to cleanly close before ending the PyTest,
Expand All @@ -10,4 +64,4 @@ def pytest_sessionfinish():
# * https://github.com/pytest-dev/pytest/issues/5282
# To prevent the exception from being raised on pytest_sessionfinish
# we disable exception raising in logging module
logging.raiseExceptions = False
logging.raiseExceptions = False
18 changes: 15 additions & 3 deletions tests/integration/standard/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ def setup_module():

# PYTHON-1328
#
# Give the cluster enough time to startup (and perform necessary initialization)
# before executing the test.
# Wait for PasswordAuthenticator to finish initializing (creating the
# default superuser). Poll by attempting to authenticate rather than
# using a fixed sleep.
if CASSANDRA_VERSION > Version('4.0-a'):
time.sleep(10)
from tests.util import wait_until_not_raised

def _check_auth_ready():
cluster = TestCluster(protocol_version=PROTOCOL_VERSION,
auth_provider=PlainTextAuthProvider('cassandra', 'cassandra'))
try:
session = cluster.connect()
session.execute("SELECT * FROM system.local WHERE key='local'")
finally:
cluster.shutdown()

wait_until_not_raised(_check_auth_ready, delay=1, max_attempts=30)

def teardown_module():
remove_cluster() # this test messes with config
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/standard/test_client_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def assert_routes_direct(test, cluster, expected_node_ids, direct_port=9042):

def setup_module():
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2 --memory 2048M"
use_cluster('test_client_routes', [3], start=True)
use_cluster('shared_aware', [3], start=True)

@skip_scylla_version_lt(reason='scylladb/scylladb#26992 - system.client_routes is not yet supported',
scylla_version="2026.1.0")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/standard/test_client_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

from cassandra.query import BatchStatement

from tests.integration import (use_singledc, PROTOCOL_VERSION, local, TestCluster,
from tests.integration import (use_single_node, PROTOCOL_VERSION, local, TestCluster,
requires_custom_payload, xfail_scylla)
from tests.util import assertRegex, assertDictEqual


def setup_module():
use_singledc()
use_single_node()

@xfail_scylla('scylladb/scylladb#10196 - scylla does not report warnings')
class ClientWarningTests(unittest.TestCase):
Expand Down
11 changes: 7 additions & 4 deletions tests/integration/standard/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


def setup_module():
os.environ['SCYLLA_EXT_OPTS'] = "--smp 1"
os.environ['SCYLLA_EXT_OPTS'] = "--smp 2"
use_cluster("cluster_tests", [3], start=True, workloads=None)
warnings.simplefilter("always")

Expand Down Expand Up @@ -720,10 +720,13 @@ def _warning_are_issued_when_auth(self, auth_provider):
session = cluster.connect()
assert session.execute("SELECT * from system.local WHERE key='local'") is not None

# Three conenctions to nodes plus the control connection
# Verify that auth warnings are issued for connections where
# auth is configured but the server does not send a challenge.
# At minimum one warning per node connection (3 for a 3-node
# cluster). The control connection and shard-aware connections
# may add more, so we only assert a lower bound.
auth_warning = mock_handler.get_message_count('warning', "An authentication challenge was not sent")
assert auth_warning >= 4
assert auth_warning == mock_handler.get_message_count("debug", "Got ReadyMessage on new connection")
assert auth_warning >= 3

def _wait_for_all_shard_connections(self, cluster, timeout=30):
"""Wait until all shard-aware connections are fully established."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def setup_module():
use_cluster('test_concurrent_schema_change_and_node_kill', [3], start=True)
use_cluster('test_schema_kill', [3], start=True)

@local
class TestConcurrentSchemaChangeAndNodeKill(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/standard/test_custom_protocol_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ContinuousPagingOptions, NoHostAvailable)
from cassandra import ProtocolVersion, ConsistencyLevel

from tests.integration import use_singledc, drop_keyspace_shutdown_cluster, \
from tests.integration import use_single_node, drop_keyspace_shutdown_cluster, \
greaterthanorequalcass30, execute_with_long_wait_retry, greaterthanorequalcass3_10, \
TestCluster, greaterthanorequalcass40
from tests.integration.datatype_utils import update_datatypes, PRIMITIVE_DATATYPES
Expand All @@ -32,7 +32,7 @@


def setup_module():
use_singledc()
use_single_node()
update_datatypes()


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/standard/test_cython_protocol_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cassandra.protocol import ProtocolHandler, LazyProtocolHandler, NumpyProtocolHandler
from cassandra.query import tuple_factory
from tests import VERIFY_CYTHON
from tests.integration import use_singledc, notprotocolv1, \
from tests.integration import use_single_node, notprotocolv1, \
drop_keyspace_shutdown_cluster, BasicSharedKeyspaceUnitTestCase, greaterthancass21, TestCluster
from tests.integration.datatype_utils import update_datatypes
from tests.integration.standard.utils import (
Expand All @@ -21,7 +21,7 @@


def setup_module():
use_singledc()
use_single_node()
update_datatypes()


Expand Down
Loading