Skip to content

Commit 6ee1334

Browse files
authored
Merge pull request datastax#943 from datastax/python-flaky-auth-tests
Wait when checking the pool status in tests
2 parents 9819499 + 4b0de5e commit 6ee1334

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

tests/integration/standard/test_authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_auth_connect(self):
9393
session = cluster.connect()
9494
try:
9595
self.assertTrue(session.execute('SELECT release_version FROM system.local'))
96-
assert_quiescent_pool_state(self, cluster)
96+
assert_quiescent_pool_state(self, cluster, wait=1)
9797
for pool in session.get_pools():
9898
connection, _ = pool.borrow_connection(timeout=0)
9999
self.assertEqual(connection.authenticator.server_authenticator_class, 'org.apache.cassandra.auth.PasswordAuthenticator')
@@ -102,7 +102,7 @@ def test_auth_connect(self):
102102
cluster.shutdown()
103103
finally:
104104
root_session.execute('DROP USER %s', user)
105-
assert_quiescent_pool_state(self, root_session.cluster)
105+
assert_quiescent_pool_state(self, root_session.cluster, wait=1)
106106
root_session.cluster.shutdown()
107107

108108
def test_connect_wrong_pwd(self):

tests/integration/util.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,23 @@
1313
# limitations under the License.
1414

1515
from tests.integration import PROTOCOL_VERSION
16+
import time
1617

17-
def assert_quiescent_pool_state(test_case, cluster):
18+
19+
def assert_quiescent_pool_state(test_case, cluster, wait=None):
20+
"""
21+
Checking the quiescent pool state checks that none of the requests ids have
22+
been lost. However, the callback corresponding to a request_id is called
23+
before the request_id is returned back to the pool, therefore
24+
25+
session.execute("SELECT * from system.local")
26+
assert_quiescent_pool_state(self, session.cluster)
27+
28+
(with no wait) might fail because when execute comes back the request_id
29+
hasn't yet been returned to the pool, therefore the wait.
30+
"""
31+
if wait is not None:
32+
time.sleep(wait)
1833

1934
for session in cluster.sessions:
2035
pool_states = session.get_pool_state().values()
@@ -34,4 +49,3 @@ def assert_quiescent_pool_state(test_case, cluster):
3449
test_case.assertEqual(connection.highest_request_id, max(req_ids))
3550
if PROTOCOL_VERSION < 3:
3651
test_case.assertEqual(connection.highest_request_id, connection.max_request_id)
37-

0 commit comments

Comments
 (0)