Skip to content

Commit b17689b

Browse files
committed
Merge pull request apache#293 from kishkaru/connect_timeout_test
[PYTHON-206] connect timeout tests
2 parents ce8765a + 6ffca60 commit b17689b

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

tests/integration/standard/test_cluster.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
WhiteListRoundRobinPolicy)
3131
from cassandra.query import SimpleStatement, TraceUnavailable
3232

33-
from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions
33+
from tests.integration import use_singledc, PROTOCOL_VERSION, get_server_versions, get_node
3434
from tests.integration.util import assert_quiescent_pool_state
3535

3636

@@ -40,6 +40,31 @@ def setup_module():
4040

4141
class ClusterTests(unittest.TestCase):
4242

43+
def test_raise_error_on_control_connection_timeout(self):
44+
"""
45+
Test for initial control connection timeout
46+
47+
test_raise_error_on_control_connection_timeout tests that the driver times out after the set initial connection
48+
timeout. It first pauses node1, essentially making it unreachable. It then attempts to create a Cluster object
49+
via connecting to node1 with a timeout of 1 second, and ensures that a NoHostAvailable is raised, along with
50+
an OperationTimedOut for 1 second.
51+
52+
@expected_errors NoHostAvailable When node1 is paused, and a connection attempt is made.
53+
@since 2.6.0
54+
@jira_ticket PYTHON-206
55+
@expected_result NoHostAvailable exception should be raised after 1 second.
56+
57+
@test_category connection
58+
"""
59+
60+
get_node(1).pause()
61+
cluster = Cluster(contact_points=['127.0.0.1'], protocol_version=PROTOCOL_VERSION, connect_timeout=1)
62+
63+
with self.assertRaisesRegexp(NoHostAvailable, "OperationTimedOut\('errors=Timed out creating connection \(1 seconds\)"):
64+
cluster.connect()
65+
66+
get_node(1).resume()
67+
4368
def test_basic(self):
4469
"""
4570
Test basic connection and usage

0 commit comments

Comments
 (0)