You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use an in-memory, shared-cache SQLite database for tests (#508)
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.
Claude-Session: https://claude.ai/code/session_01CLseCgvqE2jdan8K57ENJn
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,14 +79,17 @@ This is useful for production environments where PDF generation is expensive. Se
79
79
-**Run parallel tests with coverage**: `bundle exec rake coverage:parallel`
80
80
- Run single test: `bundle exec rspec spec/path/to/file_spec.rb:LINE_NUMBER`
81
81
- Run with verbose output: `bundle exec rspec --format documentation`
82
-
- Prepare parallel test databases: `bundle exec rails parallel:prepare`
82
+
-**Test database is in-memory**: the test env uses shared-cache in-memory
83
+
SQLite and loads `db/schema.rb` at boot (see `spec/rails_helper.rb`), so
84
+
there is no `parallel:prepare`/`db:migrate` step - each parallel worker and
85
+
each mutant kill-fork gets its own isolated in-memory database
83
86
84
87
## Environment Notes
85
88
86
89
-**ripgrep (rg) is NOT installed** - use `grep` command instead of `rg` for searching
87
90
-**Full test suite is SLOW** - only run `bundle exec rspec` when explicitly requested
88
91
- Prefer running individual test files or specific tests during development
89
-
-**Database locking**: If tests fail with "database is locked", just inform the user and wait for them to confirm it's unlocked
92
+
-**Database locking**: The test database is in-memory (no file lock). If a run still reports "database is locked", inform the user and wait for them to confirm it's unlocked
90
93
-**NEVER paste code into Rails console** - it never works. Instead write very specific RSpec tests
91
94
-**Active Storage cleanup**: Test suite automatically cleans tmp/storage before and after test runs
0 commit comments