Skip to content

Use an in-memory, shared-cache SQLite database for tests#508

Merged
stefan-burke merged 1 commit into
mainfrom
claude/mutant-gem-testing-ll69r9
Jul 3, 2026
Merged

Use an in-memory, shared-cache SQLite database for tests#508
stefan-burke merged 1 commit into
mainfrom
claude/mutant-gem-testing-ll69r9

Conversation

@stefan-burke

Copy link
Copy Markdown
Member

Summary

The test suite ran on per-worker SQLite files. Under mutant's parallel kill-forks (which all share one test file), the SQLite database lock made results non-deterministic — the Event subject flaked between 5 and 9 surviving mutations across identical runs, because a lock-timeout error during a mutation was counted as a "kill".

This switches the test environment to an in-memory, shared-cache database: file::memory:?cache=shared.

Why shared-cache

  • Plain :memory: gives every connection its own private database, which breaks any test that uses two connections — notably js: true browser tests, where the test thread writes data and Capybara's Puma server thread must read it.
  • cache=shared makes all connections within a process share one in-memory database, so browser tests keep working.
  • Shared cache is scoped per process, so parallel_test workers and mutant kill-forks are isolated automatically. There's no file and no lock, and TEST_ENV_NUMBER is no longer needed to keep workers apart.

Changes

  • config/database.ymltest now uses file::memory:?cache=shared with in-memory-appropriate pragmas (WAL/mmap dropped).
  • spec/rails_helper.rb — loads db/schema.rb into the empty in-memory DB at boot (an in-memory DB starts empty every run) instead of the file-based maintain_test_schema!, and skips the parallel-worker reconnect that would drop the shared cache and its schema.
  • .github/workflows/test-ruby.yml, coverage.yml — drop the now-unnecessary db:migrate / parallel:prepare steps (parallel:prepare actually errors against an in-memory DB); the schema loads at boot.
  • CLAUDE.md — document the in-memory test database.

Validation (all on the in-memory DB)

  • Full models, requests, services, helpers, lib, controllers, views, seeds suites: 0 failures.
  • Full features suite in parallel, including a js: true browser test driving Chromium against the Puma server: 0 failures.
  • parallel_rspec -n 2 across model specs: 0 failures, with no parallel:prepare.
  • mutant is now deterministic: three consecutive parallel runs of Event returned an identical 9 surviving mutations (92.56%) with no database is locked errors — versus the 5↔9 flakiness on files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CLseCgvqE2jdan8K57ENJn


Generated by Claude Code

The test suite ran on per-worker SQLite files. Under mutant's parallel
kill-forks that shared one file, the database lock made results
non-deterministic (a subject flaked between 5 and 9 surviving mutations
across runs).

Switch the test environment to `file::memory:?cache=shared`:

- cache=shared lets every connection in a process (the test thread and
  Capybara's Puma server thread) see the same schema and data, so browser
  (js: true) tests keep working.
- Shared cache is per-process, so parallel_test workers and mutant
  kill-forks are isolated automatically - no file, no lock. TEST_ENV_NUMBER
  is no longer needed to separate databases.
- rails_helper loads db/schema.rb into the empty in-memory database at boot
  instead of the file-based maintain_test_schema!, and skips the
  parallel-worker reconnect that would drop the shared cache.
- Drop the now-unnecessary db:migrate/parallel:prepare steps from the test
  and coverage workflows; the schema loads at boot.

Verified: the full model/request/service/helper/lib/controller/view/seed
suites and the feature suite (including a js browser test) pass, and mutant
now returns identical results across repeated parallel runs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CLseCgvqE2jdan8K57ENJn
@stefan-burke
stefan-burke added this pull request to the merge queue Jul 3, 2026
Merged via the queue into main with commit dc58acf Jul 3, 2026
17 checks passed
@stefan-burke
stefan-burke deleted the claude/mutant-gem-testing-ll69r9 branch July 3, 2026 15:57
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.

2 participants