test(testcontainers): add a DB connection-blip harness - #4862
Conversation
|
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a Postgres blip controller that terminates idle or active database backends. Exports a Merge Risk: 🔵 Low · up to 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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 💡
🧪 Generate unit tests (beta)
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. Comment |
8e76524 to
c3d185b
Compare
@trigger.dev/build
trigger.dev
@trigger.dev/core
@trigger.dev/python
@trigger.dev/react-hooks
@trigger.dev/redis-worker
@trigger.dev/rsc
@trigger.dev/schema-to-json
@trigger.dev/sdk
commit: |
c3d185b to
8d77246
Compare
8d77246 to
104b659
Compare
104b659 to
32ea701
Compare
32ea701 to
9d00c08
Compare
9d00c08 to
0dd0e0d
Compare
…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
0dd0e0d to
22b42a5
Compare
| AND pid <> pg_backend_pid() | ||
| AND backend_type = 'client backend' | ||
| AND state = 'idle'` |
There was a problem hiding this comment.
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
createDbBlipControllerand apostgresBlipTestfixture 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.