Go back to the main page

Mysql2::Error: This connection is still waiting for a result, try again once you have the result

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul

 

Getting this error when using Capybara and Rspec within specs that are :js => true?

In this case it was caused by using this code from the Capybara docs.

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

The above code, I believe, disables the connection pool, which when reading about this error seems to be one of the primary issues. Here was the solution:

    # Code is from spec_helper.rb inside of RSpec.configure block
    # Need the database_cleaner gem
    config.use_transactional_fixtures = false
    config.use_instantiated_fixtures  = false

    config.before(:each) do
      if example.metadata[:js]
        DatabaseCleaner.strategy = :truncation
      else
        DatabaseCleaner.strategy = :transaction
      end
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end

Comment on this article?