Drain fire-and-forget work before truncating test tables - #1365
Merged
Conversation
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.
✅ Deploy Preview for vortex-sandbox ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vortexfi canceled.
|
✅ Deploy Preview for vrtx-dashboard canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corridor scenario files fail at random with Postgres
deadlock detected, most often on the test that follows one that drives a ramp tocomplete. 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'sbeforeEachrunsTRUNCATE ... 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 routesenqueueRampCompletedEmailthrough the registry viamock.modulewith the usual pre-mock snapshot and restore.test-utils/db.ts:truncateAllTableswaits 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 registryharness.smoke.test.ts:truncateAllTablesdoes not proceed while tracked work is pending (deterministic reproduction of the guard)brl-offramp-crosschain.scenario.test.tsthree consecutive runs green on an isolated databaseapps/apisuite: 1615 pass, 0 fail