Skip to content

Commit 5fedc8d

Browse files
snopokeclaude
andcommitted
test(procrastinate): use async connector so run_worker can open it
SyncPsycopgConnector can defer and apply schema, but run_worker calls open_async() under the hood and raises SyncConnectorConfigurationError on sync connectors. Switching to PsycopgConnector — which docs say works in both sync and async contexts — keeps the fixture sync-friendly while making the worker happy. Also moves _fetch_job_args off the app's connector pool (now async) and opens its own psycopg connection for the read. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 46773a3 commit 5fedc8d

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

integration_tests/test_procrastinate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import random
1414

1515
import procrastinate
16+
import psycopg
1617
import pytest
1718

1819
import taskbadger
@@ -37,18 +38,19 @@ def _check_log_errors(caplog):
3738

3839
@pytest.fixture(scope="session")
3940
def app():
40-
"""A Procrastinate app pointed at a real Postgres instance with its schema applied."""
41-
conn = procrastinate.SyncPsycopgConnector(conninfo=PROCRASTINATE_DSN)
41+
# Async connector even though the tests are sync: run_worker raises
42+
# SyncConnectorConfigurationError on SyncPsycopgConnector. Async works in both contexts.
43+
conn = procrastinate.PsycopgConnector(conninfo=PROCRASTINATE_DSN)
4244
app = procrastinate.App(connector=conn)
4345
with app.open():
4446
# Apply schema (idempotent — Procrastinate's apply_schema is safe to re-run).
4547
app.schema_manager.apply_schema()
4648
yield app
4749

4850

49-
def _fetch_job_args(app, job_id):
50-
"""Read the stored ``args`` JSONB for a Procrastinate job."""
51-
with app.connector.pool.connection() as conn:
51+
def _fetch_job_args(job_id):
52+
# Direct sync psycopg connection — the app's pool is async (see fixture).
53+
with psycopg.connect(PROCRASTINATE_DSN) as conn:
5254
with conn.cursor() as cur:
5355
cur.execute("SELECT args FROM procrastinate_jobs WHERE id = %s", (job_id,))
5456
row = cur.fetchone()
@@ -75,7 +77,7 @@ def add_manual(a, b):
7577

7678
# The TB task id was stashed in the job kwargs at defer time. Read it back
7779
# from Procrastinate to verify the final state.
78-
args = _fetch_job_args(app, job_id)
80+
args = _fetch_job_args(job_id)
7981
tb_id = args["__taskbadger_task_id__"]
8082

8183
fetched = taskbadger.get_task(tb_id)
@@ -100,7 +102,7 @@ def add_auto(a, b):
100102
listen_notify=False,
101103
)
102104

103-
args = _fetch_job_args(app, job_id)
105+
args = _fetch_job_args(job_id)
104106
tb_id = args["__taskbadger_task_id__"]
105107

106108
fetched = taskbadger.get_task(tb_id)

0 commit comments

Comments
 (0)