request = <SubRequest 'winery' for <Function test_winery_sharedbase>>
postgresql = <connection object at 0x7f87a90a5548; dsn: 'user=postgres password=xxx dbname=tests host=127.0.0.1 port=11713 options=''', closed: 1>
@pytest.fixture
def winery(request, postgresql):
marker = request.node.get_closest_marker("shard_max_size")
if marker is None:
shard_max_size = 1024
else:
shard_max_size = marker.args[0]
dsn = (
f"postgres://{postgresql.info.user}"
f":@{postgresql.info.host}:{postgresql.info.port}"
)
winery = get_objstorage(
cls="winery", base_dsn=dsn, shard_dsn=dsn, shard_max_size=shard_max_size
)
yield winery
#
# del winery will get rid of all cnx to postgres that would otherwise block
# the "drop database" of the pytest-posgreql fixture (as shown by
# strace) when a test fails.
#
del winery
#
# pytest-postgresql will not remove databases that it did not create
#
d = Database(dsn)
for database in d.list_databases():
if database != postgresql.info.dbname and database != "tests_tmpl":
> d.drop_database(database)
.tox/py3/lib/python3.7/site-packages/swh/objstorage/tests/test_objstorage_winery.py:64:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <swh.objstorage.backends.winery.database.Database object at 0x7f8870799c50>
database = 'sharedbase'
def drop_database(self, database):
db = psycopg2.connect(f"{self.dsn}/postgres")
# https://wiki.postgresql.org/wiki/Psycopg2_Tutorial
# If you want to drop the database you would need to
# change the isolation level of the database.
db.set_isolation_level(0)
db.autocommit = True
c = db.cursor()
#
# Dropping the database may fail because the server takes time
# to notice a connection was dropped and/or a named cursor is
# in the process of being deleted. It can happen here or even
# when deleting all database with the psql cli
# and there are no bench process active.
#
# ERROR: database "i606428a5a6274d1ab09eecc4d019fef7" is being
# accessed by other users DETAIL: There is 1 other session
# using the database.
#
# See:
# https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
#
# https://www.postgresql.org/docs/current/sql-dropdatabase.html
#
# WITH (FORCE) added in postgresql 13 but may also fail because the
# named cursor may not be handled as a client.
#
for i in range(60):
try:
> c.execute(f"DROP DATABASE IF EXISTS {database} WITH (FORCE)")
E psycopg2.errors.SyntaxError: syntax error at or near "WITH"
E LINE 1: DROP DATABASE IF EXISTS sharedbase WITH (FORCE)
E ^
.tox/py3/lib/python3.7/site-packages/swh/objstorage/backends/winery/database.py:59: SyntaxError
TEST RESULT
TEST RESULT
- Run At
- Dec 10 2021, 11:37 PM