Repository navigation
Replay the event contract corpus over a fake native driver - #484
Merged
Merged
Conversation
…m over a fake driver capture.js --native records what passes between the JS layer and the native driver for each scenario (native-tap.js): every call, state change and result, in order, with connection strings and host names left out. A log is kept only if its run matches the corpus. test/common/fake-native.js replays such a log in place of the driver: each call JS makes is answered with what the real driver answered, released in causal order (a result waits until JS has made every call recorded before it). It also checks that the JS respects the driver: overlapping calls, calls on a released statement, calls after close, calls the recording does not have, and stalls. replay.test.js runs all 80 scenarios this way through the real JS layer, in about 20 s and without a server; every transcript matches the corpus with no violations. Against 5.6.0's lib/ it reports the pause crash (diverged: nextResultSet where the log has fetchRows), #481 (overlap: query while query in flight) and the late free (stalled), every run. ConnectionWrapper is exported so that the fake can be put under the real connection API. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Groundwork for the #479 cancel work. This tests the JS layer (queue, reader, notifier) deterministically, without a server.
What's here
Native recordings (
test/contract/native-tap.js,capture.js --native). For each corpus scenario, this records what passes between the JS layer and the native driver: every call, every statement state change, and every result, in order. A log is kept only if its run's transcript matches the corpus. Connection strings and server host names are redacted. The logs live intest/contract/native/<name>.<platform>.json: 80 scenarios, about 580 KB, Windows only so far.A replaying fake driver (
test/common/fake-native.js). It answers each call JS makes with what the real driver answered. Results are released in causal order: a result waits until JS has made every call recorded before it, so a query whose recorded result is HY008 waits for the cancel, with no timestamps needed. Independently of the recording, it checks that the JS respects the driver:overlap: a second call (a cancel apart) while one is in flight on the connectionafter release: a call on a released statementafter close: a call after the connection is closeddiverged/unrecorded: a call the recording doesn't have next, or at allstalled: JS waits on a result that waits on a call JS never makestest/contract/replay.test.jsruns every recorded scenario through the realConnectionWrapper→DriverMgr→ reader over the fake. The transcript must match the corpus, with no violations. That's 80 scenarios in about 17 s.lib/connection.jsnow exportsConnectionWrapper. That's the only change tolib/.Does it catch real bugs?
With 5.6.0's
lib/reader.js,queue.js,driver.jsandquery-handler.jsput back, it fails on every run:diverged: nextResultSet(0) made where the log has fetchRows nextafter release: nextResultSet on statement 0overlap: query while query in flightfreedelayed behind the next querystalled: JS waits on query; the log waits on releaseStatementOn the real driver, the crash showed up in about 1 run in 10.
Next
Testing
npx mocha test/contract/replay.test.js: 81 passing, 17 s (Windows).npx eslinton the new files: clean.🤖 Generated with Claude Code