From e7678931b71e1dbab0436a8a067e9db8660b91fa Mon Sep 17 00:00:00 2001 From: Vincent Bray Date: Tue, 25 Apr 2023 11:08:37 +0000 Subject: [PATCH] Expand connection pool error handling specs --- spec/lib/mysql_framework/connector_spec.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/spec/lib/mysql_framework/connector_spec.rb b/spec/lib/mysql_framework/connector_spec.rb index d652478..53364d0 100644 --- a/spec/lib/mysql_framework/connector_spec.rb +++ b/spec/lib/mysql_framework/connector_spec.rb @@ -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