Skip to content

Drain fire-and-forget work before truncating test tables - #1365

Merged
ebma merged 1 commit into
stagingfrom
fix/scenario-completion-email-race
Sep 8, 2026
Merged

Drain fire-and-forget work before truncating test tables#1365
ebma merged 1 commit into
stagingfrom
fix/scenario-completion-email-race

Conversation

@ebma

@ebma ebma commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

Corridor scenario files fail at random with Postgres deadlock detected, most often on the test that follows one that drives a ramp to complete. The phase processor enqueues the ramp-completion email without awaiting it (phase-processor.ts, enqueueRampCompletedEmail(...).catch(...)), so that INSERT can still be in flight when the next test's beforeEach runs TRUNCATE ... CASCADE. The INSERT's foreign-key check waits for a table the TRUNCATE already holds while the TRUNCATE waits for the table the INSERT holds; Postgres aborts one of them, and when it picks the TRUNCATE the next test fails.

Fix, test harness only, production behaviour unchanged:

  • test-utils/background-work.ts: a small registry (trackBackgroundWork, settleBackgroundWork).
  • test-utils/fake-world/fake-background-work.ts: the fake world routes enqueueRampCompletedEmail through the registry via mock.module with the usual pre-mock snapshot and restore.
  • test-utils/db.ts: truncateAllTables waits for tracked work to settle before truncating.
  • docs/operations-testing.md: one paragraph in the Database section.

Test plan

  • background-work.test.ts: settle waits for tracked work (resolved or rejected) and the ramp-completion enqueue is routed through the registry
  • harness.smoke.test.ts: truncateAllTables does not proceed while tracked work is pending (deterministic reproduction of the guard)
  • brl-offramp-crosschain.scenario.test.ts three consecutive runs green on an isolated database
  • Full apps/api suite: 1615 pass, 0 fail

The phase processor enqueues the ramp-completion email without awaiting
it, so the INSERT can still be in flight when the next test's beforeEach
truncates every table. Postgres then deadlocks the two (the INSERT's FK
check waits for a table the TRUNCATE holds, and vice versa) and the next
test fails at random. Route the enqueue through a background-work
registry from the fake world and have truncateAllTables wait for it.
@netlify

netlify Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit b1932fa
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6a9fcb49f7578e000813ce3f
😎 Deploy Preview https://deploy-preview-1365--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deploy Preview for vortexfi canceled.

Name Link
🔨 Latest commit b1932fa
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/6a9fcb4938d45a0008fbf6cb

@netlify

netlify Bot commented Sep 8, 2026

Copy link
Copy Markdown

Deploy Preview for vrtx-dashboard canceled.

Name Link
🔨 Latest commit b1932fa
🔍 Latest deploy log https://app.netlify.com/projects/vrtx-dashboard/deploys/6a9fcb49830b720008c08495

@ebma
ebma merged commit 2a6ac3d into staging Sep 8, 2026
6 checks passed
@ebma
ebma deleted the fix/scenario-completion-email-race branch September 8, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant