deadlock detected with capybara-webkit

后端 未结 4 717
梦谈多话
梦谈多话 2021-02-09 12:04

I\'m trying to pass this spec :

scenario \"Edit a service\", js: true do
  service = create_service_for(provider, title: \"First service\")
  fill_edit_service_f         


        
4条回答
  •  忘了有多久
    2021-02-09 12:29

    This is happening because you have two threads, the test and the request, modifying the database asynchronously. It looks like you've rightly been experimenting with different configurations in your spec_helper. I've spend a fair amount of time struggling with this same issue, and have come up with this:

    # adapted from https://gist.github.com/moonfly/4950750
    
    require 'database_cleaner'
    
    RSpec.configure do |config|
    
      config.use_transactional_fixtures = false
    
      config.before( :suite ) do
        DatabaseCleaner.clean_with :truncation
        DatabaseCleaner.strategy = :transaction
      end
    
      config.around( :each ) do |spec|
        if spec.metadata[:js]
          # JS => doesn't share connections => can't use transactions
          spec.run
          DatabaseCleaner.clean_with :deletion
        else
          # No JS/Devise => run with Rack::Test => transactions are ok
          DatabaseCleaner.start
          spec.run
          DatabaseCleaner.clean
    
          # see https://github.com/bmabey/database_cleaner/issues/99
          begin
            ActiveRecord::Base.connection.send :rollback_transaction_records, true
          rescue
          end
        end
      end
    
    end
    

    I keep it all in support/database_cleaner_configuration.rb, which would work for you, as well, or you can simply replace what you've got in your spec_helper. If this doesn't work, let me know - I have a few other ideas, but they're kookier, and not worth getting into if this works, which it probably will...

    Note:

    It might be worth mentioning that Rails 5.1+ solves the database problem. Eileen Uchitelle on the Rails team made the changes necessary to run ensure test threads and the Rails server can run in the same process by sharing the database connection.

提交回复
热议问题