File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
428447end
You can’t perform that action at this time.
0 commit comments