Fix pool_full race condition
Sometimes the main thread starts before the spawned thread, which means that the thread that is supposed to hold open a connection starts after the main thread has already successfully made a connection. This means that the test for a successful connection attempt[1] was nearly useless since the main thread would get the connection first and activate it[2] no matter how long the spawned thread waited, and the test for a failed connection attempt[3] would intermittently fail since is sometimes able to get the connection before the busy-waiting worker thread does. Adding a short sleep in the main thread ensures that the main thread yields to the worker thread and it can grab the connection first so we can actually test what happens in the main thread. [1] http://git.openstack.org/cgit/openstack/ldappool/tree/ldappool/tests/test_ldappool.py#n183 [2] http://git.openstack.org/cgit/openstack/ldappool/tree/ldappool/__init__.py#n167 [3] http://git.openstack.org/cgit/openstack/ldappool/tree/ldappool/tests/test_ldappool.py#n193 Change-Id: Ic32ef931cd672907dd14d5ec6339a6d7d9a2018d
This commit is contained in:
parent
feed0a08c8
commit
b08b776fdc
|
@ -149,7 +149,6 @@ class TestLDAPSQLAuth(unittest.TestCase):
|
|||
cn = worker.results[0][0][1]['cn']
|
||||
self.assertEqual(cn, ['admin'])
|
||||
|
||||
@unittest.skip("race conditions make this fail the gate")
|
||||
def test_pool_full(self):
|
||||
dn = 'uid=adminuser,ou=logins,dc=mozilla'
|
||||
passwd = 'adminuser'
|
||||
|
@ -169,6 +168,7 @@ class TestLDAPSQLAuth(unittest.TestCase):
|
|||
time.sleep(self.duration)
|
||||
|
||||
def tryit():
|
||||
time.sleep(0.1)
|
||||
with pool.connection() as conn: # NOQA
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue