Repository navigation
test(sim): mock the database as a transport, with injected rollbacks - #114
Merged
Merged
Conversation
kyscott18
force-pushed
the
feat/db-pglite
branch
from
November 2, 2026 21:22
49ebafe to
f2f530c
Compare
kyscott18
force-pushed
the
test/sim-db-transport
branch
from
November 2, 2026 21:22
251d2c2 to
174406f
Compare
kyscott18
marked this pull request as ready for review
November 2, 2026 21:23
The simulation's database mock wraps a `DbTransport`, under the runtime's real `makeDbClient`, as `sim-rpc.ts` sits under `layerRpc`. The runtime's retry policy now runs in the simulation. `SIM.db.errorRate` ([0, 0.01, 0.05]) is how often a transaction rolls back after `f` ran, as on a serialization failure at `COMMIT` (`notApplied`), so the client runs `f` again from the start. Each client attempt draws once, keyed by the statements it ran and how many times it ran them. A flake of the real database retries inside `io`, on the real clock, then dies, as `chain.ts` does for Anvil, so only drawn rollbacks reach the runtime and a flake moves neither virtual time nor the runtime's draws. A drawn rollback leaves `io` as `InjectedRollback`, which the flake retry passes by, and reaches the client as a `DbError` after the latency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kyscott18
force-pushed
the
test/sim-db-transport
branch
from
November 2, 2026 21:28
174406f to
bd82647
Compare
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.
The sim's database mock (
makeSimDbTransport) now wraps aDbTransportand sits under the runtime's realmakeDbClient(#112), the waymakeSimTransportsits underlayerRpc. Before, it wrapped the finishedDb, so the runtime's retry policy never ran in the sim. Latency,iogating and the no-clock/no-random rules inside a transaction are unchanged.makeDbClientis now exported.Injected errors.
SIM.db.errorRateis picked per seed from[0, 0.01, 0.05]. With that probability, a transaction rolls back afterfran. The runtime seesDbError({ sql: "COMMIT", notApplied: true }), as on a serialization failure atCOMMIT, and runsfagain from the start. That exercises the client's retries and the "fcan run more than once" contract onDb.notApplied: false). That stops the runtime, so it only makes sense once the sim simulates restarts.Flakes stay out of the simulation. A real database failure with
notAppliedretries insideio, on the real clock (exponential from 10 ms, 5 times), then dies, aschain.tsdoes for Anvil. Only drawn rollbacks reach the runtime, so a flake can't move virtual time or the runtime's seeded draws.ioasInjectedRollback, which the flake retry passes by, and becomes theDbErroronly after the latency.fagain records its statements from scratch and reuses that attempt's draw.Checked (Postgres, sequential, on a937227):
bun testwithDATABASE_URL: 97 pass.0xe 0x11 0x41 0xa0pass and draw no rollbacks.0xe,0x41and0xa0matchmainexactly (virtual time, submissions, blocks, batches).reorgRate: [0]patch, seed0x01(rate 0.05) passes full validation with 51 injected rollbacks.Math.random, before and afterf). Runs of0x01that absorbed 105 and 130 flakes were identical to the clean run.🤖 Generated with Claude Code