Skip to content

Commit 84c1fa7

Browse files
committed
test for min/max requests validation
PYTHON-220
1 parent f08b772 commit 84c1fa7

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

tests/unit/test_cluster.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
from mock import patch, Mock
2121

22+
2223
from cassandra import ConsistencyLevel, DriverException, Timeout, Unavailable, RequestExecutionException, ReadTimeout, WriteTimeout, CoordinationFailure, ReadFailure, WriteFailure, FunctionFailure, AlreadyExists,\
2324
InvalidRequest, Unauthorized, AuthenticationFailed, OperationTimedOut, UnsupportedOperation, RequestValidationException, ConfigurationException
2425
from cassandra.cluster import _Scheduler, Session, Cluster
26+
from cassandra.policies import HostDistance
2527
from cassandra.query import SimpleStatement
2628

2729

@@ -79,21 +81,35 @@ def test_exception_types(self):
7981
self.assertTrue(issubclass(UnsupportedOperation, DriverException))
8082

8183

82-
class ContactListTest(unittest.TestCase):
84+
class ClusterTest(unittest.TestCase):
8385

84-
def test_invalid_types(self, *args):
86+
def test_invalid_contact_point_types(self):
8587
with self.assertRaises(ValueError):
8688
Cluster(contact_points=[None], protocol_version=4, connect_timeout=1)
8789
with self.assertRaises(TypeError):
8890
Cluster(contact_points="not a sequence", protocol_version=4, connect_timeout=1)
8991

92+
def test_requests_in_flight_threshold(self):
93+
d = HostDistance.LOCAL
94+
mn = 3
95+
mx = 5
96+
c = Cluster(protocol_version=2)
97+
c.set_min_requests_per_connection(d, mn)
98+
c.set_max_requests_per_connection(d, mx)
99+
# min underflow, max, overflow
100+
for n in (-1, mx, 127):
101+
self.assertRaises(ValueError, c.set_min_requests_per_connection, d, n)
102+
# max underflow, under min, overflow
103+
for n in (0, mn, 128):
104+
self.assertRaises(ValueError, c.set_max_requests_per_connection, d, n)
105+
90106

91107
class SchedulerTest(unittest.TestCase):
92108
# TODO: this suite could be expanded; for now just adding a test covering a ticket
93109

94110
@patch('time.time', return_value=3) # always queue at same time
95111
@patch('cassandra.cluster._Scheduler.run') # don't actually run the thread
96-
def test_event_delay_timing(self, *args):
112+
def test_event_delay_timing(self, *_):
97113
"""
98114
Schedule something with a time collision to make sure the heap comparison works
99115
@@ -108,7 +124,7 @@ class SessionTest(unittest.TestCase):
108124
# TODO: this suite could be expanded; for now just adding a test covering a PR
109125

110126
@patch('cassandra.cluster.ResponseFuture._make_query_plan')
111-
def test_default_serial_consistency_level(self, *args):
127+
def test_default_serial_consistency_level(self, *_):
112128
"""
113129
Make sure default_serial_consistency_level passes through to a query message.
114130
Also make sure Statement.serial_consistency_level overrides the default.

0 commit comments

Comments
 (0)