test: add direct unit coverage for closeDbPair/closeDbPairDeferred/closeDbDeferred#1862
Conversation
…oseDbDeferred closeDbPair, closeDbPairDeferred, and closeDbDeferred in src/db/connection.ts had zero direct test coverage despite being core resource-lifecycle primitives in a fanIn-55 file — the same category of gap where the openReadonlyWithNative leak went undetected (see openReadonlyWithNative-leak.test.ts). Adds three describe blocks to tests/unit/db.test.ts, alongside the existing openDb/closeDb coverage: - closeDbPair: native handle closes before the better-sqlite3 handle; a native close failure doesn't prevent the better-sqlite3 close; works with no native handle present. - closeDbPairDeferred: native closes synchronously within the call, while the better-sqlite3 close is deferred via closeDbDeferred (including when the native close throws). - closeDbDeferred: the advisory lock releases synchronously (verified via a real lock file), the handle itself closes on the next tick, and flushDeferredClose() closes it synchronously when called first — with the originally scheduled callback correctly skipping a second close. Fixes #1751
Greptile SummaryThis PR adds 10 unit tests covering three previously untested resource-lifecycle helpers —
Confidence Score: 5/5Pure test addition with no production code changes; all new tests correctly model the source functions they exercise. Every new test was traced against the corresponding implementation in connection.ts — close ordering, try/catch resilience, setImmediate deferral, the double-close guard (indexOf check), and advisory-lock release timing all match the production code exactly. The afterEach cleanup pattern correctly drains the module-level _deferredDbs singleton between tests. No production code was touched. No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "test: add direct unit coverage for close..." | Re-trigger Greptile |
Summary
closeDbPair,closeDbPairDeferred, andcloseDbDeferredhad zero direct test coverage despite being core resource-lifecycle primitives in a fanIn-55 file — exactly the kind of gap an earlier phase's real resource-leak bug slipped through.tests/unit/db.test.ts(existing home for this file's connection tests): close ordering (native before better-sqlite3, survives native-close failure), deferred-close timing (native immediate, better-sqlite3 deferred to next tick), and advisory-lock release/flush semantics (immediate lock release,flushDeferredClose()closes synchronously with no double-close).Closes #1751
Test plan
npm test— full suite green (3500 passed, 0 failed), all 10 new tests confirmed running and passing (not skipped)npm run lint/npm run typecheck— cleanStacked on #1861 (base branch
fix/issue-1750-finddbpath-swallowed-errors) — only the test diff is this issue's change.