allow new connections right away if pool can be increased

This commit is contained in:
Brian J. Cardiff 2016-10-22 19:14:18 -03:00
parent 56aa10c54d
commit 3a7c801ece
2 changed files with 13 additions and 0 deletions

View file

@ -87,4 +87,14 @@ describe DB::Database do
DummyDriver::DummyConnection.connections.size.should eq(2)
end
end
it "should allow new connections if pool can increased and retry is not allowed" do
DummyDriver::DummyConnection.clear_connections
DB.open "dummy://localhost:1027?initial_pool_size=1&max_pool_size=2&retry_attempts=0" do |db|
db.query("stmt1")
DummyDriver::DummyConnection.connections.size.should eq(1)
db.query("stmt1")
DummyDriver::DummyConnection.connections.size.should eq(2)
end
end
end

View file

@ -80,6 +80,9 @@ module DB
# but if a new connection is needed there is a `retry_delay` seconds delay.
def retry
current_available = @available.size
# if the pool hasn't reach the max size, allow 1 attempt
# to make a new connection if needed without sleeping
current_available += 1 if can_increase_pool
(current_available + @retry_attempts).times do |i|
begin