From 0f2fe424f65f9f1fd2acfc926ebe1df1447c456b Mon Sep 17 00:00:00 2001 From: Dotta Date: Tue, 15 Sep 2026 23:56:41 -0500 Subject: [PATCH] Drain background failure reports before asserting Sentry events Co-Authored-By: Paperclip --- server/src/__tests__/native-session-resumption.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/__tests__/native-session-resumption.test.ts b/server/src/__tests__/native-session-resumption.test.ts index 14f340e3d32..70125e2bf23 100644 --- a/server/src/__tests__/native-session-resumption.test.ts +++ b/server/src/__tests__/native-session-resumption.test.ts @@ -40,6 +40,7 @@ import { } from "../vendor/paperclip-runner/testing.js"; import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; import { drainHeartbeatRunsToQuiescence } from "./helpers/drain-heartbeat-runs.js"; +import { waitForPendingRunFailureReports } from "../services/run-failure-report.js"; import { claimNativeSessionResumptions, dispatchNativeSessionResumptions, @@ -563,10 +564,9 @@ describe("P6-25 pre-result native session recovery", () => { const captureCallsBefore = mockCaptureRunFailure.mock.calls.length; await claimNativeSessionResumptions({ db, runnerInstanceId: "reaper", runIds: [freshRunId] }); - // The Sentry report fires without an await inside the reconciler, so a - // follow-up round trip to the real database gives that fire-and-forget - // call room to complete before this test reads the spy. - await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, freshRunId)); + // The reconciler reports asynchronously; an unrelated database round trip + // does not guarantee that callback has completed. + await waitForPendingRunFailureReports(); const newCaptures = mockCaptureRunFailure.mock.calls.slice(captureCallsBefore); expect(newCaptures).toHaveLength(1); @@ -601,7 +601,7 @@ describe("P6-25 pre-result native session recovery", () => { const captureCallsBefore = mockCaptureRunFailure.mock.calls.length; await claimNativeSessionResumptions({ db, runnerInstanceId: "reaper", runIds: [freshRunId] }); - await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, freshRunId)); + await waitForPendingRunFailureReports(); expect(mockCaptureRunFailure.mock.calls.slice(captureCallsBefore)).toHaveLength(0); });