diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-08 16:36:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-08 16:36:46 -0700 |
commit | 16e4d013d8a264aed99deeba18d96a1ac541a715 (patch) | |
tree | b3ce722bb52e79a34d8572edf2dc9ff88fe544cf | |
parent | 2e0b0c1dab7eeafb58d29ac6e71071118c91365f (diff) | |
download | rails-16e4d013d8a264aed99deeba18d96a1ac541a715.tar.gz rails-16e4d013d8a264aed99deeba18d96a1ac541a715.tar.bz2 rails-16e4d013d8a264aed99deeba18d96a1ac541a715.zip |
close our connection when we are done
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 24 |
2 files changed, 17 insertions, 14 deletions
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 5c7751b445..4bcc97ec44 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -56,7 +56,10 @@ class DefaultScopingTest < ActiveRecord::TestCase 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 @@ class DefaultScopingTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 6ba7464203..c0cad52b22 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -526,22 +526,20 @@ if current_adapter?(:PostgreSQLAdapter) # 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. |