From 249d22e41fe88023d7166961004d81eb6011c1d3 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 9 Oct 2026 16:07:17 -0400 Subject: [PATCH] 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 --- tests/integration/test_alert_email_outbox.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_alert_email_outbox.py b/tests/integration/test_alert_email_outbox.py index d092d14..42981fa 100644 --- a/tests/integration/test_alert_email_outbox.py +++ b/tests/integration/test_alert_email_outbox.py @@ -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")