diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-04-27 15:26:35 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-04-27 15:26:35 -0400 |
commit | 1b63306a973f13588216fbb097b6dffb4a5c4c63 (patch) | |
tree | 99d94f40b8c9b697cca738c8a44299e2893d1573 /test/engine/test_pool.py | |
parent | 63ff0140705207198545e3a0d7868a5ba8486e93 (diff) | |
download | sqlalchemy-1b63306a973f13588216fbb097b6dffb4a5c4c63.tar.gz |
- try to work around a race that can occur in STP when
used in this intentionally broken scenario
Change-Id: I88ea6fa710da2189e6d47e2d12f5f0fd6f6bb7d4
Diffstat (limited to 'test/engine/test_pool.py')
-rw-r--r-- | test/engine/test_pool.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 1fbaf5965..ffbb5f282 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -2016,12 +2016,21 @@ class SingletonThreadPoolTest(PoolTestBase): return dbapi.connect() p = pool.SingletonThreadPool(creator=creator, pool_size=3) + # there's an obvious race in STP which is that one thread + # creates a connection, another one calls cleanup and closes + # it before it ever gets returned. This is of course if you're + # using more threads than the pool can connect to. + if strong_refs: sr = set() def _conn(): c = p.connect() - sr.add(c.connection) + if not c.connection.close.call_count: + sr.add(c.connection) + # otherwise the connection is already closed, which + # is because you're using 10 threads but only a pool + # of size 3 :). return c else: def _conn(): @@ -2042,7 +2051,7 @@ class SingletonThreadPoolTest(PoolTestBase): threads.append(th) for th in threads: th.join(join_timeout) - assert len(p._all_conns) == 3 + eq_(len(p._all_conns), 3) if strong_refs: still_opened = len([c for c in sr if not c.close.call_count]) |