Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 668d43b053f5f651b66357b3599e4bdec2c4a9e3 Mon Sep 17 00:00:00 2001
- From: Nick Sieger <nick@nicksieger.com>
- Date: Thu, 4 Sep 2008 15:16:29 +0200
- Subject: [PATCH] Default connection allow_concurrency to false (for PostgreSQL)
- ---
- .../abstract/connection_pool.rb | 3 +--
- activerecord/lib/active_record/test_case.rb | 15 +++++++++++++++
- activerecord/test/cases/locking_test.rb | 2 ++
- activerecord/test/cases/transactions_test.rb | 2 ++
- 4 files changed, 20 insertions(+), 2 deletions(-)
- diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
- index 6b4bc25..5806dea 100644
- --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
- +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
- @@ -164,8 +164,7 @@ module ActiveRecord
- private
- def new_connection
- - config = spec.config.reverse_merge(:allow_concurrency => true)
- - ActiveRecord::Base.send(spec.adapter_method, config)
- + ActiveRecord::Base.send(spec.adapter_method, spec.config)
- end
- def current_connection_id #:nodoc:
- diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb
- index ffaa412..eabf06f 100644
- --- a/activerecord/lib/active_record/test_case.rb
- +++ b/activerecord/lib/active_record/test_case.rb
- @@ -43,5 +43,20 @@ module ActiveRecord
- def assert_no_queries(&block)
- assert_queries(0, &block)
- end
- +
- + def self.use_concurrent_connections
- + setup :connection_allow_concurrency_setup
- + teardown :connection_allow_concurrency_teardown
- + end
- +
- + def connection_allow_concurrency_setup
- + @connection = ActiveRecord::Base.remove_connection
- + ActiveRecord::Base.establish_connection(@connection.merge({:allow_concurrency => true}))
- + end
- +
- + def connection_allow_concurrency_teardown
- + ActiveRecord::Base.clear_all_connections!
- + ActiveRecord::Base.establish_connection(@connection)
- + end
- end
- end
- diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
- index bbe8582..0a14b1d 100644
- --- a/activerecord/test/cases/locking_test.rb
- +++ b/activerecord/test/cases/locking_test.rb
- @@ -257,6 +257,8 @@ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
- end
- if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
- + use_concurrent_connections
- +
- def test_no_locks_no_wait
- first, second = duel { Person.find 1 }
- assert first.end > second.end
- diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
- index a8016cd..b12ec36 100644
- --- a/activerecord/test/cases/transactions_test.rb
- +++ b/activerecord/test/cases/transactions_test.rb
- @@ -284,6 +284,8 @@ end
- if current_adapter?(:PostgreSQLAdapter)
- class ConcurrentTransactionTest < TransactionTest
- + use_concurrent_connections
- +
- # This will cause transactions to overlap and fail unless they are performed on
- # separate database connections.
- def test_transaction_per_thread
- --
- 1.5.6
Add Comment
Please, Sign In to add comment