Created
July 4, 2012 19:30
Revisions
-
mperham revised this gist
Jul 4, 2012 . 1 changed file with 8 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,9 @@ Capybara uses two threads to run client and server. If you just cargo cult the DatabaseCleaner code that is floating around, you can run into https://github.com/brianmario/mysql2/issues/99 because the threads will occasionally use the same connection at the same time. The fix is to use a single connection but protect access to it by having each thread "check out" the connection when they are using it. This is trivial to do with the `connection_pool` gem. Add it to your Gemfile and use the "after" code above. -
mperham revised this gist
Jul 4, 2012 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Capybara uses two threads to run client and server. If you just cargo cult the DatabaseCleaner code that is floating around, you can run into https://github.com/brianmario/mysql2/issues/99 because the threads will occasionally use the same connection at the same time. The fix is to use a single connection but protect access to it by having each thread "check out" the connection when they are using it. This is trivial to do with the `connection_pool` gem. -
mperham revised this gist
Jul 4, 2012 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ 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 -
mperham created this gist
Jul 4, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection } end end ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection