Skip to content

Commit

Permalink
Expand connection pool error handling specs
Browse files Browse the repository at this point in the history
  • Loading branch information
noodl committed Apr 25, 2023
1 parent 5106550 commit e767893
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions spec/lib/mysql_framework/connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,22 @@
end
end

describe 'connection pool error handling' do
describe 'when connection pool is exhausted' do
before do
expect(subject).to_not receive(:check_in)
max_pool_size.times { subject.check_out }
end

it 'does not add nil to the pool when full and an attempt is made to use it' do
conns = max_pool_size.times.map { subject.check_out }
expect { subject.query('select 1') }.to raise_error(RuntimeError)
# Previous versions had a bug where a nil would be added to the pool
# at this point.
expect { subject.connections.pop(true) } .to raise_error(ThreadError)
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 e767893

Please sign in to comment.