summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-02-14 12:05:07 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-02-14 12:05:07 +0000
commitf802ad370e625e7aa2f3023f73c24a8b6f009821 (patch)
tree4c19328a336cfbdc8e522d7983f35b334c6aa7fd /spec/lib/gitlab/database_spec.rb
parent1cac06c4e811ddbfeed8f699cb29ba37394916fb (diff)
parent03f1abfcc3e43fce188f94a770f5f7b6af6f36b5 (diff)
downloadgitlab-ce-f802ad370e625e7aa2f3023f73c24a8b6f009821.tar.gz
Merge branch 'create-connection-pool' into 'master'
Introduce Gitlab::Database.with_connection_pool See merge request !9192
Diffstat (limited to 'spec/lib/gitlab/database_spec.rb')
-rw-r--r--spec/lib/gitlab/database_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb
index 41252f31997..f01c42aff91 100644
--- a/spec/lib/gitlab/database_spec.rb
+++ b/spec/lib/gitlab/database_spec.rb
@@ -77,6 +77,54 @@ describe Gitlab::Database, lib: true do
end
end
+ describe '.with_connection_pool' do
+ it 'creates a new connection pool and disconnect it after used' do
+ closed_pool = nil
+
+ described_class.with_connection_pool(1) do |pool|
+ pool.with_connection do |connection|
+ connection.execute('SELECT 1 AS value')
+ end
+
+ expect(pool).to be_connected
+
+ closed_pool = pool
+ end
+
+ expect(closed_pool).not_to be_connected
+ end
+
+ it 'disconnects the pool even an exception was raised' do
+ error = Class.new(RuntimeError)
+ closed_pool = nil
+
+ begin
+ described_class.with_connection_pool(1) do |pool|
+ pool.with_connection do |connection|
+ connection.execute('SELECT 1 AS value')
+ end
+
+ closed_pool = pool
+
+ raise error.new('boom')
+ end
+ rescue error
+ end
+
+ expect(closed_pool).not_to be_connected
+ end
+ end
+
+ describe '.create_connection_pool' do
+ it 'creates a new connection pool with specific pool size' do
+ pool = described_class.create_connection_pool(5)
+
+ expect(pool)
+ .to be_kind_of(ActiveRecord::ConnectionAdapters::ConnectionPool)
+ expect(pool.spec.config[:pool]).to eq(5)
+ end
+ end
+
describe '#true_value' do
it 'returns correct value for PostgreSQL' do
expect(described_class).to receive(:postgresql?).and_return(true)