Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion providers/fab/tests/unit/fab/auth_manager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ def factory():
_app.config["AUTH_ROLE_PUBLIC"] = None
return _app

return factory()
flask_app = factory()
try:
yield flask_app
finally:
# Dispose the flask_sqlalchemy per-app engine so its pooled connections
# don't survive the session in long CI runs.
with flask_app.app_context():
for fab_engine in flask_app.extensions["sqlalchemy"].engines.values():
fab_engine.dispose()


@pytest.fixture
Expand Down
11 changes: 9 additions & 2 deletions providers/fab/tests/unit/fab/auth_manager/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,15 @@ def app():
):
_app = application.create_app(enable_plugins=False)
_app.config["WTF_CSRF_ENABLED"] = False
with _app.app_context():
yield _app
try:
with _app.app_context():
yield _app
finally:
# Dispose the flask_sqlalchemy per-app engine so its pooled
# connections don't survive the module in long CI runs.
with _app.app_context():
for fab_engine in _app.extensions["sqlalchemy"].engines.values():
fab_engine.dispose()


@pytest.fixture(scope="module")
Expand Down
11 changes: 10 additions & 1 deletion providers/fab/tests/unit/fab/www/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ def app():
): "airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager",
}
):
yield application.create_app(enable_plugins=False)
flask_app = application.create_app(enable_plugins=False)
try:
yield flask_app
finally:
# flask_sqlalchemy creates a per-app engine in init_app(); a
# function-scoped app fixture without disposal would leak that
# engine's connection pool every test.
with flask_app.app_context():
for fab_engine in flask_app.extensions["sqlalchemy"].engines.values():
fab_engine.dispose()


@pytest.mark.parametrize(
Expand Down
11 changes: 10 additions & 1 deletion providers/fab/tests/unit/fab/www/views/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@

@pytest.fixture(autouse=True, scope="module")
def session():
settings.configure_orm()
# reconfigure_orm() disposes any pre-existing engine before creating a new
# one. Plain configure_orm() leaks the previous engine's connection pool,
# which exhausts Postgres max_connections in long parallel CI runs.
settings.reconfigure_orm()
return settings.Session


Expand Down Expand Up @@ -102,6 +105,12 @@ def factory():

for user_dict in test_users:
delete_user(app, user_dict["username"])
# flask_sqlalchemy creates a per-app engine in init_app(); without disposal
# its pooled connections survive the fixture and accumulate across modules
# in long CI runs.
with app.app_context():
for fab_engine in app.extensions["sqlalchemy"].engines.values():
fab_engine.dispose()


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ def app():
):
app = application.create_app(enable_plugins=False)
app.config["WTF_CSRF_ENABLED"] = False
yield app
try:
yield app
finally:
# flask_sqlalchemy creates a per-app engine in init_app(); a
# function-scoped app fixture without disposal would leak that
# engine's connection pool every test.
with app.app_context():
for fab_engine in app.extensions["sqlalchemy"].engines.values():
fab_engine.dispose()


@pytest.fixture
Expand Down
Loading