Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 71420fd

Browse files
committed
tests: fix sql_alchemy_db fixture for timescale
there's a deadlock error that happens where the timescale background worker is running background jobs and we're altering the schema of the tables on which it's running the background job on, so we stop the background worker momentarily to allow the migrations to run.
1 parent dba53c5 commit 71420fd

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,23 @@ def sqlalchemy_db(request: pytest.FixtureRequest, django_db_blocker, django_db_s
122122
original_test_name = settings.DATABASES["default"]["TEST"]["NAME"]
123123
settings.DATABASES["default"]["NAME"] = "sqlalchemy"
124124
settings.DATABASES["default"]["TEST"]["NAME"] = "test_postgres_sqlalchemy"
125+
for connection in connections:
126+
if "timeseries" in connection:
127+
with connections[connection].cursor() as cursor:
128+
cursor.execute(
129+
"SELECT _timescaledb_internal.stop_background_workers();"
130+
)
125131
db_cfg = setup_databases(
126132
verbosity=request.config.option.verbose,
127133
interactive=False,
128134
keepdb=keepdb,
129135
)
136+
for connection in connections:
137+
if "timeseries" in connection:
138+
with connections[connection].cursor() as cursor:
139+
cursor.execute(
140+
"SELECT _timescaledb_internal.start_background_workers();"
141+
)
130142
settings.DATABASES["default"]["NAME"] = original_db_name
131143
settings.DATABASES["default"]["TEST"]["NAME"] = original_test_name
132144

0 commit comments

Comments
 (0)