Skip to content

Commit 58abbbf

Browse files
committed
Wait when checking the pool status in tests
1 parent bb31bb7 commit 58abbbf

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

tests/integration/standard/test_authentication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from tests.integration import use_singledc, get_cluster, remove_cluster, PROTOCOL_VERSION, CASSANDRA_IP, \
2222
set_default_cass_ip
23-
from tests.integration.util import assert_quiescent_pool_state
23+
from tests.integration.util import assert_quiescent_pool_state, assert_quiescent_pool_state_with_wait
2424

2525
try:
2626
import unittest2 as unittest
@@ -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_with_wait(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_with_wait(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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
# limitations under the License.
1414

1515
from tests.integration import PROTOCOL_VERSION
16+
import time
17+
18+
19+
def assert_quiescent_pool_state_with_wait(test_case, cluster, wait):
20+
"""
21+
This function is useful for waiting before checking the pool state.
22+
assert_quiescent_pool_state checks that none of the requests ids have got lost.
23+
However the callback corresponding to a request_id is called before the request_id
24+
is returned back to the pool, therfore
25+
26+
session.execute("SELECT * from system.local")
27+
assert_quiescent_pool_state(self, session.cluster)
28+
29+
might fail because when execute comes back the request_id hasn't yet been
30+
returned to the pool, therefore the wait.
31+
"""
32+
time.sleep(wait)
33+
assert_quiescent_pool_state(test_case, cluster)
34+
1635

1736
def assert_quiescent_pool_state(test_case, cluster):
1837

0 commit comments

Comments
 (0)