Sha256: 88cb89371c5a29539721df12949ad030ae31eae107e27828e59968a548675ae0

Contents?: true

Size: 1.58 KB

Versions: 26

Compression:

Stored size: 1.58 KB

Contents

# Test that the bug in AR ConnectionPool is fixed, either becuase of a local
# patch (temporarily in config/initializers/patch/connection_pool.rb)
# or because of a future version of Rails. 
# See https://github.com/rails/rails/issues/5330

require 'test_helper'

class ActiveRecordConnectionPoolTest < Test::Unit::TestCase

  def test_threaded_with_connection
        # Neccesary to have a checked out connection in thread
        # other than one we will test, in order to trigger bug
        # we are testing fix for.
        main_thread_conn = ActiveRecord::Base.connection_pool.checkout

        aThread = Thread.new do
          ActiveRecord::Base.connection_pool.with_connection do
            ActiveRecord::Base.connection # need to do something AR to trigger the checkout

            reserved_thread_ids = ActiveRecord::Base.connection_pool.instance_variable_get(:@reserved_connections)

            assert reserved_thread_ids.has_key?( Thread.current.object_id ), "thread should be in reserved connections"
          end
          reserved_thread_ids = ActiveRecord::Base.connection_pool.instance_variable_get(:@reserved_connections)
          assert !reserved_thread_ids.has_key?( Thread.current.object_id ), "thread should not be in reserved connections"
        end
        aThread.join

        ActiveRecord::Base.connection_pool.checkin main_thread_conn

        reserved_thread_ids = ActiveRecord::Base.connection_pool.instance_variable_get(:@reserved_connections)
        assert !reserved_thread_ids.has_key?( aThread.object_id ), "thread should not be in reserved connections"
      end
  
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
umlaut-3.3.1 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.3.0 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.2.0 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.1.1 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.1.0 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.1.0.pre2 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.1.0.pre1 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.5 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.4 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.3 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.2 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.1 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0rc1 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta10 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta9 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta8 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta7 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta6 ./test/unit/active_record_connection_pool_test.rb
umlaut-3.0.0beta5 ./test/unit/active_record_connection_pool_test.rb