test(email): the deleted-alerts outbox test stays in one event loop (#5507)
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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user