Skip to content

Commit e767893

Browse files
committed
Expand connection pool error handling specs
1 parent 5106550 commit e767893

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

spec/lib/mysql_framework/connector_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,22 @@
426426
end
427427
end
428428

429-
describe 'connection pool error handling' do
429+
describe 'when connection pool is exhausted' do
430430
before do
431-
expect(subject).to_not receive(:check_in)
431+
max_pool_size.times { subject.check_out }
432432
end
433433

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

0 commit comments

Comments
 (0)