From 6ffca60cd1291277fd05967b9dbeecd764b9c615 Mon Sep 17 00:00:00 2001 From: Kishan Karunaratne Date: Fri, 1 May 2015 16:29:02 -0700 Subject: [PATCH] test for python-206 connect timeouts --- tests/integration/standard/test_cluster.py | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/integration/standard/test_cluster.py b/tests/integration/standard/test_cluster.py index 0fcabd10..146859ba 100644 --- a/tests/integration/standard/test_cluster.py +++ b/tests/integration/standard/test_cluster.py @@ -30,7 +30,7 @@ from cassandra.policies import (RoundRobinPolicy, ExponentialReconnectionPolicy, WhiteListRoundRobinPolicy) from cassandra.query import SimpleStatement, TraceUnavailable -from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions +from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions, get_node from tests.integration.util import assert_quiescent_pool_state @@ -40,6 +40,31 @@ def setup_module(): class ClusterTests(unittest.TestCase): + def test_raise_error_on_control_connection_timeout(self): + """ + Test for initial control connection timeout + + test_raise_error_on_control_connection_timeout tests that the driver times out after the set initial connection + timeout. It first pauses node1, essentially making it unreachable. It then attempts to create a Cluster object + via connecting to node1 with a timeout of 1 second, and ensures that a NoHostAvailable is raised, along with + an OperationTimedOut for 1 second. + + @expected_errors NoHostAvailable When node1 is paused, and a connection attempt is made. + @since 2.6.0 + @jira_ticket PYTHON-206 + @expected_result NoHostAvailable exception should be raised after 1 second. + + @test_category connection + """ + + get_node(1).pause() + cluster = Cluster(contact_points=['127.0.0.1'], protocol_version=PROTOCOL_VERSION, connect_timeout=1) + + with self.assertRaisesRegexp(NoHostAvailable, "OperationTimedOut\('errors=Timed out creating connection \(1 seconds\)"): + cluster.connect() + + get_node(1).resume() + def test_basic(self): """ Test basic connection and usage