Skip to content

Commit 1d98c86

Browse files
authored
Merge pull request #41 from Sage/connection-pool-full-error-handling
Empty connection pool error handling
2 parents c2cff39 + e767893 commit 1d98c86

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/mysql_framework/connector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def with_client(provided = nil)
7777
client = provided || check_out
7878
yield client
7979
ensure
80-
check_in(client) unless provided
80+
check_in(client) if client && !provided
8181
end
8282

8383
# This method is called to execute a prepared statement

spec/lib/mysql_framework/connector_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,23 @@
425425
end
426426
end
427427
end
428+
429+
describe 'when connection pool is exhausted' do
430+
before do
431+
max_pool_size.times { subject.check_out }
432+
end
433+
434+
it 'pop throws exception' do
435+
expect { subject.connections.pop(true) }.to raise_error(ThreadError)
436+
end
437+
438+
it 'throws exception on query' do
439+
expect { subject.query('SELECT 1') }.to raise_error(RuntimeError, /depleted/)
440+
end
441+
442+
it 'does not put nil in the pool on error' do
443+
expect(subject).to_not receive(:check_in).with(nil)
444+
expect { subject.query('SELECT 1') }.to raise_error(RuntimeError, /depleted/)
445+
end
446+
end
428447
end

0 commit comments

Comments
 (0)