Skip to content

test(testcontainers): add a DB connection-blip harness - #4862

Open
d-cs wants to merge 1 commit into
mainfrom
tri-13551-db-blip-test-harness
Open

test(testcontainers): add a DB connection-blip harness#4862
d-cs wants to merge 1 commit into
mainfrom
tri-13551-db-blip-test-harness

Conversation

@d-cs

@d-cs d-cs commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a test-only harness for simulating a Postgres connection blip, so tests can prove their database code survives a dropped connection. It exports createDbBlipController and a postgresBlipTest fixture from @internal/testcontainers.

How it works

The harness severs connections from a separate admin connection using pg_terminate_backend, scoped to the test's own database, so it composes with any Prisma client under test and stays isolated across parallel tests. Two modes:

  • severIdle() kills idle backends. A pooled (driver-adapter) client absorbs this transparently: the pool evicts the dead connection and the next query just works.
  • severDuringNextStatement() kills a statement mid-flight, surfacing a connection error to the caller; the client then recovers on the next retry.

The bundled tests demonstrate both, plus the correctness property that matters before adding retries anywhere: a non-idempotent write double-applies when retried after a post-commit blip, while an idempotent write (deterministic id plus ON CONFLICT) stays at exactly one row.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 22b42a5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@d-cs d-cs self-assigned this Sep 1, 2026
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a Postgres blip controller that terminates idle or active database backends. Exports a postgresBlipTest fixture with controller lifecycle management. Adds PostgreSQL adapter dependencies and tests for connection recovery, in-flight statement failures, read retries, and idempotent versus non-idempotent writes after connection termination.

Merge Risk: 🔵 Low · up to 9d00c

This change adds a private test harness that can terminate PostgreSQL sessions to simulate connection failures. The standard fixture is isolated, but the directly exported helper can affect unrelated sessions if given a shared database connection, so the PR is mergeable with owner awareness or follow-up to keep that capability scoped to test-owned databases.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description accurately explains the harness, its isolation model, supported failure modes, and test coverage. However, it omits the required template sections for issue closure, checklist, testing… Update the description to include the required template sections. Add the issue reference, complete the checklist, document the commands and results used to test the change, provide a short changelog entry, and state whether screenshots are…
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of a testcontainers database connection-blip harness and follows the repository convention.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description accurately explains the harness, its isolation model, supported failure modes, and test coverage. However, it omits the required template sections for issue closure, checklist, testing steps, changelog, and screenshots.

Resolution

Update the description to include the required template sections. Add the issue reference, complete the checklist, document the commands and results used to test the change, provide a short changelog entry, and state whether screenshots are applicable.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tri-13551-db-blip-test-harness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 8e76524 to c3d185b Compare September 1, 2026 13:55
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@22b42a5

trigger.dev

npm i https://pkg.pr.new/trigger.dev@22b42a5

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@22b42a5

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@22b42a5

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@22b42a5

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@22b42a5

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@22b42a5

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@22b42a5

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@22b42a5

commit: 22b42a5

coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from c3d185b to 8d77246 Compare September 1, 2026 14:33
coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 8d77246 to 104b659 Compare September 1, 2026 14:54
coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 104b659 to 32ea701 Compare September 1, 2026 15:05
@d-cs
d-cs marked this pull request as ready for review September 2, 2026 08:31
devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 32ea701 to 9d00c08 Compare September 2, 2026 08:55
devin-ai-integration[bot]

This comment was marked as resolved.

@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 9d00c08 to 0dd0e0d Compare September 2, 2026 08:59
coderabbitai[bot]

This comment was marked as resolved.

…ests

Adds DbBlipController + a postgresBlipTest fixture that sever a test
Postgres connection via pg_terminate_backend, so a vertical can prove
its DB code survives a disconnect without a proxy or extra container.

Includes tests that exercise the harness: a severed read fails, an
in-flight statement is terminated mid-flight, a non-idempotent write
double-applies on retry while the idempotent form does not, and a
pg-driver-adapter client recovers a model read through a blip.

TRI-13551
@d-cs
d-cs force-pushed the tri-13551-db-blip-test-harness branch from 0dd0e0d to 22b42a5 Compare September 2, 2026 11:08

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Devin Review

Comment on lines +53 to +55
AND pid <> pg_backend_pid()
AND backend_type = 'client backend'
AND state = 'idle'`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Multiple controllers can sever each other

When two controllers share one database, severIdle can terminate the other controller's idle admin connection. Direct users then lose one harness unexpectedly.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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