mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-25 18:12:47 -04:00
1e278de4cc
Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
from sqlalchemy import pool as pool_module
|
|
from sqlalchemy.pool import QueuePool
|
|
from sqlalchemy.testing import AssertsExecutionResults
|
|
from sqlalchemy.testing import fixtures
|
|
from sqlalchemy.testing import profiling
|
|
|
|
|
|
pool = None
|
|
|
|
|
|
class QueuePoolTest(fixtures.TestBase, AssertsExecutionResults):
|
|
__requires__ = ("cpython",)
|
|
|
|
class Connection(object):
|
|
def rollback(self):
|
|
pass
|
|
|
|
def close(self):
|
|
pass
|
|
|
|
def teardown(self):
|
|
# the tests leave some fake connections
|
|
# around which don't necessarily
|
|
# get gc'ed as quickly as we'd like,
|
|
# on backends like pypy, python3.2
|
|
pool_module._refs.clear()
|
|
|
|
def setup(self):
|
|
# create a throwaway pool which
|
|
# has the effect of initializing
|
|
# class-level event listeners on Pool,
|
|
# if not present already.
|
|
p1 = QueuePool(
|
|
creator=self.Connection,
|
|
pool_size=3,
|
|
max_overflow=-1,
|
|
use_threadlocal=True,
|
|
)
|
|
p1.connect()
|
|
|
|
global pool
|
|
pool = QueuePool(
|
|
creator=self.Connection,
|
|
pool_size=3,
|
|
max_overflow=-1,
|
|
use_threadlocal=True,
|
|
)
|
|
|
|
@profiling.function_call_count()
|
|
def test_first_connect(self):
|
|
pool.connect()
|
|
|
|
def test_second_connect(self):
|
|
conn = pool.connect()
|
|
conn.close()
|
|
|
|
@profiling.function_call_count()
|
|
def go():
|
|
conn2 = pool.connect()
|
|
return conn2
|
|
|
|
go()
|
|
|
|
def test_second_samethread_connect(self):
|
|
conn = pool.connect()
|
|
conn # strong ref
|
|
|
|
@profiling.function_call_count()
|
|
def go():
|
|
return pool.connect()
|
|
|
|
go()
|