Skip to content

Close the sqlite connections tests leaked - #232

Merged
ajslater merged 1 commit into
developfrom
claude/angry-knuth-afa2b9
Oct 4, 2026
Merged

ajslater merged 1 commit into
developfrom
claude/angry-knuth-afa2b9

Conversation

@ajslater

@ajslater ajslater commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Summary

A coverage-enabled make test reported 12 ResourceWarning: unclosed database in <sqlite3.Connection> warnings, attributed to test_metron_id_attribute_fallback.py and test_write_api.py. That attribution is only where garbage collection happened to run; it moved between runs.

To find the openers, a throwaway pytest plugin (not committed) swapped in a sqlite3.Connection subclass that records the opening test and stack, and logs any connection collected while still open. It traced all 12 to three test files. None is a production leak:

File Leaks Cause Fix
tests/unit/test_vacuum.py 6 with sqlite3.connect(...) commits on exit but never closes closing(...). The small-file test now opens in autocommit, as _make_bloated_db already does, so its writes still land without the old implicit commit
tests/unit/test_cover_hash.py 4 three tests never closed their CoverHashUrlCache; one read the table back via a bare with sqlite3.connect cache.close() (the file's existing convention) and closing(...)
tests/unit/test_quota_reserved_skip.py 2 search() builds the shared Metron session before the gate check under test, which opened mokkari's SqliteCache (no close() in 4.9.0) stub _get_session in the shared _source helper, as test_a_healthy_budget_records_no_reason already did

Hermeticity hole found along the way

The two quota tests opened the developer's real ~/.cache/comicbox/online/metron_cache.sqlite. OnlineSettings() built directly in a test has cache.dir=None, which resolves to the platformdirs cache. The conftest pins COMICBOX_ONLINE__CACHE__DIR, but only config-loaded settings read that variable. After this change no test in the suite opens a sqlite file under the real home cache (checked with the same plugin). The hole itself is still there for future tests that build OnlineSettings() directly.

Test plan

  • make test on current develop + this commit: 2390 passed, 1 skipped, 0 ResourceWarning (was 12). The 5 remaining warnings are pymupdf's SWIG DeprecationWarnings, which predate this change.
  • Tracking plugin over the full suite: 0 connections collected while open, 0 opens under the real home cache
  • make fix (no changes), make lint, make ty clean

🤖 Generated with Claude Code

A coverage run of the suite reported 12 `ResourceWarning: unclosed
database` warnings, attributed to whichever test garbage collection
happened to run in. Tagging every connection with the test that opened
it traced all 12 to three files:

- test_vacuum.py (6): `with sqlite3.connect(...)` only commits on exit;
  it never closes. Wrap in `closing()`. The small-file test now opens in
  autocommit, as the bloated-db helper already does, so its writes still
  land without the commit the bare context manager used to supply.
- test_cover_hash.py (4): three tests never closed their
  CoverHashUrlCache, and one read the table back through a bare
  `with sqlite3.connect`.
- test_quota_reserved_skip.py (2): `search()` builds the shared Metron
  session before the gate check under test, which opened mokkari's
  SqliteCache (no close) in the developer's real platformdirs cache --
  `OnlineSettings()` carries no cache dir, so the conftest's env-var pin
  does not reach it. Stub `_get_session` in the shared helper, as one
  test already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ajslater
ajslater merged commit a48fd79 into develop Oct 4, 2026
7 checks passed
@ajslater
ajslater deleted the claude/angry-knuth-afa2b9 branch October 6, 2026 20:43
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