test(email): the deleted-alerts outbox test stays in one event loop (#5507)
CI / lint (push) Successful in 2s
CI / integration (push) Successful in 1m10s
CI / unit (push) Successful in 1m27s
CI / publish (push) Successful in 1m15s

Run 8942 failed this test alone (118 passed): it read the row back in a
second asyncio.run, and the app's pooled connection belonged to the
first, closed loop. The behaviour held ("The alerts this email carried
were deleted"); the settled row is now read from attempt's own result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 16:07:17 -04:00
co-authored by Claude Opus 5.5
parent 9a3e7ddba2
commit 249d22e41f
+4 -10
View File
@@ -156,14 +156,8 @@ def test_an_email_whose_alerts_were_deleted_fails_and_says_so(app, monkeypatch):
async with s.begin():
await s.execute(delete(AlertEvent).where(AlertEvent.id == ev))
done = await outbox.attempt(app, [row.id])
return done[row.id].state, row.id
return done[row.id]
state, rid = asyncio.run(_go())
assert state == "failed"
async def _reason():
from steward.models.outbox import EmailOutbox
async with app.db_sessionmaker() as s:
return (await s.get(EmailOutbox, rid)).last_error
assert asyncio.run(_reason()) == "The alerts this email carried were deleted"
# One event loop per test: the app's pool is bound to the loop it ran in.
row = asyncio.run(_go())
assert (row.state, row.last_error) == ("failed", "The alerts this email carried were deleted")