File: test_timed_stack_subclassing.rb

package info (click to toggle)
ruby-connection-pool 2.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188 kB
  • sloc: ruby: 1,235; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 954 bytes parent folder | download
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
# frozen_string_literal: true

require_relative "helper"

class TestTimedStackSubclassing < Minitest::Test
  def setup
    @klass = Class.new(ConnectionPool::TimedStack)
  end

  def test_try_fetch_connection
    obj = Object.new
    stack = @klass.new(1) { obj }
    assert_equal false, stack.send(:try_fetch_connection)
    assert_equal obj, stack.pop
    stack.push obj
    assert_equal obj, stack.send(:try_fetch_connection)
  end

  def test_override_try_fetch_connection
    obj = Object.new

    stack = @klass.new(1) { obj }
    stack.push stack.pop

    connection_stored_called = "cs_called"
    stack.define_singleton_method(:connection_stored?) { |*| raise connection_stored_called }
    e = assert_raises { stack.send(:try_fetch_connection) }
    assert_equal connection_stored_called, e.message

    stack.define_singleton_method(:try_fetch_connection) { fetch_connection }
    assert_equal obj, stack.send(:try_fetch_connection)
  end
end