Permalink
Browse files

Can't get DummyPool to work properly either.

  • Loading branch information...
1 parent f600125 commit a3610cc57afe8e499b4557fe01eb6dc2019d2897 @kgaughan committed Sep 23, 2012
Showing with 0 additions and 81 deletions.
  1. +0 −44 dbkit.py
  2. +0 −37 tests/test_pools.py
View
@@ -411,46 +411,6 @@ def finalise(self):
self._cond.release()
-class DummyPool(PoolBase):
- """
- This pool only imposes limits on the number of connections that can be
- held open concurrently. Connections are closed as soon as the context
- they are being used in is exited.
-
- Type 0 drivers force `max_conns` to be set to 1. Other driver types allow
- more than one concurrent connection.
- """
-
- __slots = ('_semaphore',)
-
- def __init__(self, module, max_conns, *args, **kwargs):
- threadsafety = 0 if max_conns == 1 else 1
- super(DummyPool, self).__init__(module, threadsafety, args, kwargs)
- self._semaphore = threading.Semaphore(max_conns)
-
- def acquire(self):
- self._semaphore.acquire()
- try:
- return self._connect()
- except:
- self._semaphore.release()
- raise
-
- def release(self, conn):
- # pylint: disable-msg=W0702
- try:
- conn.close()
- except: # pragma: no cover
- pass
- self._semaphore.release()
-
- def discard(self):
- self._semaphore.release()
-
- def finalise(self):
- pass
-
-
def _make_connect(module, args, kwargs):
"""
Returns a function capable of making connections with a particular
@@ -481,10 +441,6 @@ def create_pool(module, max_conns, *args, **kwargs):
raise ValueError("Minimum number of connections is 1.")
if module.threadsafety >= 2:
return Pool(module, max_conns, *args, **kwargs)
- #if module.threadsafety >= 1:
- # return ThreadAffinePool(module, max_conns, *args, **kwargs)
- if module.threadsafety >= 0:
- return DummyPool(module, 1, *args, **kwargs)
raise ValueError("Bad threadsafety level: %d", module.threadsafety)
View
@@ -87,43 +87,6 @@ def wait_on_connection():
assert len(pool._pool) == 0
-def test_dummy_pool_contention():
- pool = dbkit.DummyPool(fakedb, 1, fakedb.INVALID_CURSOR)
- # Here, we're testing that the pool behaves properly when it hits its
- # maximum number of connections and a thread it waiting for another one
- # to release the connection it's currently using.
- release = threading.Event()
- spawn = threading.Event()
-
- def hog_connection():
- with pool.connect() as ctx:
- with dbkit.transaction():
- spawn.set()
- release.wait()
-
- def wait_on_connection():
- with pool.connect() as ctx:
- spawn.wait()
- # Request the other thread to release the connection after a
- # short period, enough to ensure the conditional variable
- # managing the pool is waited on by this thread. Basically
- # nearly any pause should be long enough, though 1/100 of a
- # second seems like a reasonable balance.
- #
- # We do this because we want to deterministically introduce a
- # wait on the condition variable that signals when there's a free
- # connection. In normal operation, this happens in a
- # nondeterministic manner. This pause and the use of the release
- # and spawn events ensure that the threads proceed in lockstep
- # to produce the behaviour we need to set.
- threading.Timer(1.0 / 100, lambda: release.set()).start()
- with dbkit.transaction():
- pass
- utils.spawn([wait_on_connection, hog_connection])
-
- pool.finalise()
-
-
def test_setting_propagation():
pool = dbkit.Pool(fakedb, 1, fakedb.INVALID_CURSOR)
try:

0 comments on commit a3610cc

Please sign in to comment.