rails / solid_cache

A database-backed ActiveSupport::Cache::Store
MIT License
888 stars 62 forks source link

Error "cache database is not configured for the test environment" when eager loading #216

Closed mattbrictson closed 2 months ago

mattbrictson commented 2 months ago

I generated a brand new Rails 8 app like this:

rails new solidsolid --main -d postgresql --skip-action-mailbox --skip-action-text

After creating a test, when I run CI=1 bin/rails test, Rails fails to boot with the following error:

rails-e1d58cfd05ae/activerecord/lib/active_record/database_configurations.rb:229:in `resolve_symbol_connection': The `cache` database is not configured for the `test` environment. (ActiveRecord::AdapterNotSpecified)

  Available database configurations are:

  default
development
test
production: primary, cache, queue

It seems that when eager loading is enabled (CI=1 enables eager loading in the test environment), solid_cache loads its models and attempts to connect to the database, which doesn't exist in the test environment. This is despite the fact that solid cache is not be used as the cache store in test.

# config/environments/test.rb
Rails.application.configure do
  config.eager_load = ENV["CI"].present?
  config.cache_store = :null_store
end

Full backtrace:

``` /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/database_configurations.rb:229:in `resolve_symbol_connection': The `cache` database is not configured for the `test` environment. (ActiveRecord::AdapterNotSpecified) Available database configurations are: default development test production: primary, cache, queue from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/database_configurations.rb:179:in `resolve' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:391:in `resolve_config_for_connection' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:100:in `block (2 levels) in connects_to' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:99:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:99:in `block in connects_to' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:98:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/activerecord/lib/active_record/connection_handling.rb:98:in `connects_to' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/solid_cache-1.0.5/app/models/solid_cache/record.rb:9:in `' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/solid_cache-1.0.5/app/models/solid_cache/record.rb:4:in `' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/solid_cache-1.0.5/app/models/solid_cache/record.rb:3:in `
' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:26:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/solid_cache-1.0.5/app/models/solid_cache/entry.rb:4:in `' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/solid_cache-1.0.5/app/models/solid_cache/entry.rb:3:in `
' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:26:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:180:in `const_get' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:180:in `block in actual_eager_load_dir' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:47:in `block in ls' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:25:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/helpers.rb:25:in `ls' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:168:in `actual_eager_load_dir' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:17:in `block (2 levels) in eager_load' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:16:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:16:in `block in eager_load' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:10:in `synchronize' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader/eager_load.rb:10:in `eager_load' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader.rb:413:in `block in eager_load_all' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader.rb:411:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/loader.rb:411:in `eager_load_all' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/application/finisher.rb:80:in `block in ' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/initializable.rb:32:in `instance_exec' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/initializable.rb:32:in `run' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/initializable.rb:61:in `block in run_initializers' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `call' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/initializable.rb:60:in `run_initializers' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/application.rb:440:in `initialize!' from /Users/mbrictson/Code/scratch/solidsolid/config/environment.rb:5:in `
' from /Users/mbrictson/Code/scratch/solidsolid/test/test_helper.rb:2:in `require_relative' from /Users/mbrictson/Code/scratch/solidsolid/test/test_helper.rb:2:in `
' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require' from /Users/mbrictson/Code/scratch/solidsolid/test/helpers/hello_test.rb:1:in `
' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/test_unit/runner.rb:62:in `block in load_tests' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/test_unit/runner.rb:60:in `each' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/test_unit/runner.rb:60:in `load_tests' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/test_unit/runner.rb:52:in `run' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/commands/test/test_command.rb:33:in `perform' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/command/base.rb:178:in `invoke_command' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/command/base.rb:73:in `perform' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/command.rb:71:in `block in invoke' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/command.rb:149:in `with_argv' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/command.rb:69:in `invoke' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/rails-e1d58cfd05ae/railties/lib/rails/commands.rb:18:in `
' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/3.3.0/bundled_gems.rb:75:in `block (2 levels) in replace_require' from /Users/mbrictson/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require' from bin/rails:4:in `
' ```