aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb
blob: 1fd64dd0afbc4838f783d32600a5c1881fdeda97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class AbstractAdapterTest < ActiveRecord::TestCase
      attr_reader :adapter

      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_not adapter.lease, 'should not lease adapter'
      end

      def test_last_use
        assert_not adapter.last_use
        adapter.lease
        assert adapter.last_use
      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 = ConnectionPool.new(ConnectionSpecification.new({}, 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