Skip to content
This repository
Browse code

close our connection when we are done

  • Loading branch information...
commit 16e4d013d8a264aed99deeba18d96a1ac541a715 1 parent 2e0b0c1
Aaron Patterson authored July 08, 2013
7  activerecord/test/cases/scoping/default_scoping_test.rb
@@ -56,7 +56,10 @@ def test_default_scope_with_conditions_hash
56 56
 
57 57
   def test_default_scoping_with_threads
58 58
     2.times do
59  
-      Thread.new { assert DeveloperOrderedBySalary.all.to_sql.include?('salary DESC') }.join
  59
+      Thread.new {
  60
+        assert DeveloperOrderedBySalary.all.to_sql.include?('salary DESC')
  61
+        DeveloperOrderedBySalary.connection.close
  62
+      }.join
60 63
     end
61 64
   end
62 65
 
@@ -360,9 +363,11 @@ def test_default_scope_is_threadsafe
360 363
     threads << Thread.new do
361 364
       Thread.current[:long_default_scope] = true
362 365
       assert_equal 1, ThreadsafeDeveloper.all.to_a.count
  366
+      ThreadsafeDeveloper.connection.close
363 367
     end
364 368
     threads << Thread.new do
365 369
       assert_equal 1, ThreadsafeDeveloper.all.to_a.count
  370
+      ThreadsafeDeveloper.connection.close
366 371
     end
367 372
     threads.each(&:join)
368 373
   end
24  activerecord/test/cases/transactions_test.rb
@@ -526,22 +526,20 @@ class ConcurrentTransactionTest < TransactionTest
526 526
     # This will cause transactions to overlap and fail unless they are performed on
527 527
     # separate database connections.
528 528
     def test_transaction_per_thread
529  
-      assert_nothing_raised do
530  
-        threads = (1..3).map do
531  
-          Thread.new do
532  
-            Topic.transaction do
533  
-              topic = Topic.find(1)
534  
-              topic.approved = !topic.approved?
535  
-              topic.save!
536  
-              topic.approved = !topic.approved?
537  
-              topic.save!
538  
-            end
539  
-            Topic.connection.close
  529
+      threads = 3.times.map do
  530
+        Thread.new do
  531
+          Topic.transaction do
  532
+            topic = Topic.find(1)
  533
+            topic.approved = !topic.approved?
  534
+            assert topic.save!
  535
+            topic.approved = !topic.approved?
  536
+            assert topic.save!
540 537
           end
  538
+          Topic.connection.close
541 539
         end
542  
-
543  
-        threads.each { |t| t.join }
544 540
       end
  541
+
  542
+      threads.each { |t| t.join }
545 543
     end
546 544
 
547 545
     # Test for dirty reads among simultaneous transactions.

1 note on commit 16e4d01

Akira Matsuda
Collaborator

@tenderlove This commit broke rake test_sqlite3_mem

Please sign in to comment.
Something went wrong with that request. Please try again.