Skip to content

Commit

Permalink
Use separate methods for stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Holland authored and mperham committed Aug 8, 2017
1 parent 8ac6a0c commit cd6f0e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def shutdown(&block)
@available.shutdown(&block)
end

def stats
{
size: @available.max,
available: @available.length
}
def max_connection_count
@available.max
end

def available_connection_count
@available.length
end

private
Expand Down
5 changes: 3 additions & 2 deletions test/test_connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,15 @@ def test_wrapper_with_connection_pool
def test_stats_without_active_connection
pool = ConnectionPool.new(size: 2) { NetworkConnection.new }

assert_equal({ size: 2, available: 2 }, pool.stats)
assert_equal(2, pool.max_connection_count)
assert_equal(2, pool.available_connection_count)
end

def test_stats_with_active_connection
pool = ConnectionPool.new(size: 2) { NetworkConnection.new }

pool.with do
assert_equal({ size: 2, available: 1 }, pool.stats)
assert_equal(1, pool.available_connection_count)
end
end
end

0 comments on commit cd6f0e0

Please sign in to comment.