Default connection allow_concurrency to false (for PostgreSQL)

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Nick Sieger
2008-09-04 15:16:29 +02:00
committed by Jeremy Kemper
parent 2c62baf4bf
commit a3f12f575d
4 changed files with 20 additions and 2 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -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