Skip to content

Commit

Permalink
Merge pull request #41 from Sage/connection-pool-full-error-handling
Browse files Browse the repository at this point in the history
Empty connection pool error handling
  • Loading branch information
noodl authored Sep 12, 2024
2 parents c2cff39 + e767893 commit 1d98c86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mysql_framework/connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def with_client(provided = nil)
client = provided || check_out
yield client
ensure
check_in(client) unless provided
check_in(client) if client && !provided
end

# This method is called to execute a prepared statement
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/mysql_framework/connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,23 @@
end
end
end

describe 'when connection pool is exhausted' do
before do
max_pool_size.times { subject.check_out }
end

it 'pop throws exception' do
expect { subject.connections.pop(true) }.to raise_error(ThreadError)
end

it 'throws exception on query' do
expect { subject.query('SELECT 1') }.to raise_error(RuntimeError, /depleted/)
end

it 'does not put nil in the pool on error' do
expect(subject).to_not receive(:check_in).with(nil)
expect { subject.query('SELECT 1') }.to raise_error(RuntimeError, /depleted/)
end
end
end

0 comments on commit 1d98c86

Please sign in to comment.