Open workmaster2n opened 9 years ago
Similar issue here, just that rspec is completely hanging so I needed to do this trick and found DatabaseCleaner.clean_with(:truncation, { except: %w[spatial_ref_sys] })
as the line causing the problem.
Here's the complete database_cleaner.rb
file:
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation, { except: %w[spatial_ref_sys] })
end
config.prepend_before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end
end
UPDATE:
Here's the entire output:
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `call'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activesupport-5.0.0.rc2/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/referential_integrity.rb:15:in `block in disable_referential_integrity'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.rc2/lib/active_record/connection_adapters/postgresql/referential_integrity.rb:14:in `disable_referential_integrity'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/database_cleaner-1.5.3/lib/database_cleaner/active_record/truncation.rb:235:in `clean'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/database_cleaner-1.5.3/lib/database_cleaner/base.rb:46:in `clean_with'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `block in clean_with'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `each'
/Users/MyUser/.rvm/gems/ruby-2.2.3/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `clean_with'
/Users/MyUser/path/to/my/project/spec/support/database_cleaner.rb:4:in `block (2 levels) in <top (required)>'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/example.rb:441:in `instance_exec'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/example.rb:441:in `instance_exec'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/hooks.rb:350:in `run'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/configuration.rb:1880:in `block in run_hooks_with'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/configuration.rb:1880:in `each'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/configuration.rb:1880:in `run_hooks_with'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/configuration.rb:1836:in `with_suite_hooks'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/runner.rb:112:in `block in run_specs'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/reporter.rb:77:in `report'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/runner.rb:111:in `run_specs'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/runner.rb:87:in `run'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/runner.rb:71:in `run'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/lib/rspec/core/runner.rb:45:in `invoke'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bundler/gems/rspec-core-fe1256b4c51e/exe/rspec:4:in `<top (required)>'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `load'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bin/rspec:23:in `<main>'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
/Users/MyUser/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'
Maybe this isn't an issue with database_clenaer after all, couldn't this be an issue with the pg gem itself? See https://bitbucket.org/ged/ruby-pg/issues/75/hang-in-pgconn-block-while-waiting-for.
I believe this is a problem with ActiveRecord as mentioned here.
I've fixed this for my problems by adding the following monkey patch in test_helper.rb. I also use :truncation and no transactional fixtures
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module ReferentialIntegrity # :nodoc:
def supports_disable_referential_integrity? # :nodoc:
false
end
end
end
end
end
Initially, my tests took 30 mins to run, but by adding the :pre_count option it dropped back to a more reasonable 7 mins.
We use the PostGIS extension and the rgeo AR gem. We use truncation for our
js
tests as well as ourbefore(:suite)
strategy.The problem is that the PostGIS extension creates a table
spatial_ref_sys
that is owned by the user who installs the extension (namely, a super user).Running
bundle exec rspec
fails with the following error:The error comes from the call to
disable_referential_integrity
because it calls all tables, ignoring any tables that might have beenexclude
d via thetruncation
options.Our
database_cleaner.rb
file:One workaround is to execute the tests as a db super user. Another would be to change the ownership of the
spatial_ref_system
table. Neither of these are very desirable.Is there a way to skip tables in the
disable_referential_integrity
call?