Skip to content

Commit

Permalink
Add file locking to Snowflake DB session fixture to prevent concurren…
Browse files Browse the repository at this point in the history
…t access
  • Loading branch information
Aleksandr Movchan committed Dec 11, 2024
1 parent f4fceee commit 321375c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions aana/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import portpicker
import pytest
from filelock import FileLock
from pytest_postgresql import factories
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -230,13 +231,15 @@ def snowflake_db_session():
# Reset the engine
aana_settings.db_config._engine = None

# Run migrations to set up the schema
run_alembic_migrations(aana_settings)
# Use the lock to ensure only one test uses the Snowflake session at a time
with FileLock("/tmp/snowflake_test.lock"): # noqa: S108
# Run migrations to set up the schema
run_alembic_migrations(aana_settings)

# Create a new session
engine = aana_settings.db_config.get_engine()
with Session(engine) as session:
yield session
# Create a new session
engine = aana_settings.db_config.get_engine()
with Session(engine) as session:
yield session


@pytest.fixture(
Expand Down

0 comments on commit 321375c

Please sign in to comment.