Sha256: 39b054cfd09b11edc80917f9cd479934ad0109688ab1b22d2c9cf00c6692ed09

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class AdapterLeasingTest < ActiveRecord::TestCase
      class Pool < ConnectionPool
        def insert_connection_for_test!(c)
          synchronize do
            adopt_connection(c)
            @available.add c
          end
        end
      end

      def setup
        @adapter = AbstractAdapter.new nil, nil
      end

      def test_in_use?
        assert_not @adapter.in_use?, 'adapter is not in use'
        assert @adapter.lease, 'lease adapter'
        assert @adapter.in_use?, 'adapter is in use'
      end

      def test_lease_twice
        assert @adapter.lease, 'should lease adapter'
        assert_raises(ActiveRecordError) do
          @adapter.lease
        end
      end

      def test_expire_mutates_in_use
        assert @adapter.lease, 'lease adapter'
        assert @adapter.in_use?, 'adapter is in use'
        @adapter.expire
        assert_not @adapter.in_use?, 'adapter is in use'
      end

      def test_close
        pool = Pool.new(ConnectionSpecification.new("primary", {}, nil))
        pool.insert_connection_for_test! @adapter
        @adapter.pool = pool

        # Make sure the pool marks the connection in use
        assert_equal @adapter, pool.connection
        assert @adapter.in_use?

        # Close should put the adapter back in the pool
        @adapter.close
        assert_not @adapter.in_use?

        assert_equal @adapter, pool.connection
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ibm_db-5.2.0 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-5.1.0 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-5.0.5 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-5.0.4 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-5.0.3 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-5.0.2 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-4.0.0-x86-mingw32 test/cases/connection_adapters/adapter_leasing_test.rb
ibm_db-4.0.0 test/cases/connection_adapters/adapter_leasing_test.rb