提交 16e4d013 编写于 作者: A Aaron Patterson

close our connection when we are done

上级 2e0b0c1d
......@@ -56,7 +56,10 @@ def test_default_scope_with_conditions_hash
def test_default_scoping_with_threads
2.times do
Thread.new { assert DeveloperOrderedBySalary.all.to_sql.include?('salary DESC') }.join
Thread.new {
assert DeveloperOrderedBySalary.all.to_sql.include?('salary DESC')
DeveloperOrderedBySalary.connection.close
}.join
end
end
......@@ -360,9 +363,11 @@ def test_default_scope_is_threadsafe
threads << Thread.new do
Thread.current[:long_default_scope] = true
assert_equal 1, ThreadsafeDeveloper.all.to_a.count
ThreadsafeDeveloper.connection.close
end
threads << Thread.new do
assert_equal 1, ThreadsafeDeveloper.all.to_a.count
ThreadsafeDeveloper.connection.close
end
threads.each(&:join)
end
......
......@@ -526,22 +526,20 @@ class ConcurrentTransactionTest < TransactionTest
# This will cause transactions to overlap and fail unless they are performed on
# separate database connections.
def test_transaction_per_thread
assert_nothing_raised do
threads = (1..3).map do
Thread.new do
Topic.transaction do
topic = Topic.find(1)
topic.approved = !topic.approved?
topic.save!
topic.approved = !topic.approved?
topic.save!
end
Topic.connection.close
threads = 3.times.map do
Thread.new do
Topic.transaction do
topic = Topic.find(1)
topic.approved = !topic.approved?
assert topic.save!
topic.approved = !topic.approved?
assert topic.save!
end
Topic.connection.close
end
threads.each { |t| t.join }
end
threads.each { |t| t.join }
end
# Test for dirty reads among simultaneous transactions.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册