summaryrefslogtreecommitdiff
path: root/spec/initializers/database_config_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-30 12:06:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-30 12:06:34 +0000
commit228d752ff09362002cc904d28edee7d63cc3cef2 (patch)
tree63e7ff466c0b0794f67c87c34e874f8682fb5de0 /spec/initializers/database_config_spec.rb
parentb539ac1d619c0aafe5988ab8b125a8b43b14d87f (diff)
downloadgitlab-ce-228d752ff09362002cc904d28edee7d63cc3cef2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/initializers/database_config_spec.rb')
-rw-r--r--spec/initializers/database_config_spec.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb
new file mode 100644
index 00000000000..a5a074f5884
--- /dev/null
+++ b/spec/initializers/database_config_spec.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Database config initializer' do
+ subject do
+ load Rails.root.join('config/initializers/database_config.rb')
+ end
+
+ before do
+ allow(ActiveRecord::Base).to receive(:establish_connection)
+ end
+
+ context "when using Puma" do
+ let(:puma) { double('puma') }
+ let(:puma_options) { { max_threads: 8 } }
+
+ before do
+ stub_const("Puma", puma)
+ allow(puma).to receive_message_chain(:cli_config, :options).and_return(puma_options)
+ end
+
+ context "and no existing pool size is set" do
+ before do
+ stub_database_config(pool_size: nil)
+ end
+
+ it "sets it to the max number of worker threads" do
+ expect { subject }.to change { Gitlab::Database.config['pool'] }.from(nil).to(8)
+ end
+ end
+
+ context "and the existing pool size is smaller than the max number of worker threads" do
+ before do
+ stub_database_config(pool_size: 7)
+ end
+
+ it "sets it to the max number of worker threads" do
+ expect { subject }.to change { Gitlab::Database.config['pool'] }.from(7).to(8)
+ end
+ end
+
+ context "and the existing pool size is larger than the max number of worker threads" do
+ before do
+ stub_database_config(pool_size: 9)
+ end
+
+ it "keeps the configured pool size" do
+ expect { subject }.not_to change { Gitlab::Database.config['pool'] }
+ end
+ end
+ end
+
+ context "when not using Puma" do
+ before do
+ stub_database_config(pool_size: 7)
+ end
+
+ it "does nothing" do
+ expect { subject }.not_to change { Gitlab::Database.config['pool'] }
+ end
+ end
+
+ def stub_database_config(pool_size:)
+ config = {
+ 'adapter' => 'postgresql',
+ 'host' => 'db.host.com',
+ 'pool' => pool_size
+ }.compact
+
+ allow(Gitlab::Database).to receive(:config).and_return(config)
+ end
+end