From 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Aug 2020 18:42:06 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-3-stable-ee --- spec/initializers/database_config_spec.rb | 72 +++++++++++++------------------ 1 file changed, 30 insertions(+), 42 deletions(-) (limited to 'spec/initializers/database_config_spec.rb') diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index 29d499efcd3..ccd69de0b3a 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -9,65 +9,53 @@ RSpec.describe 'Database config initializer' do before do allow(ActiveRecord::Base).to receive(:establish_connection) + allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads) end - context "when using multi-threaded runtime" do - let(:max_threads) { 8 } + let(:max_threads) { 8 } + context "no existing pool size is set" do before do - allow(Gitlab::Runtime).to receive(:multi_threaded?).and_return(true) - allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads) + stub_database_config(pool_size: nil) 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(max_threads) - end + it "sets it based on the max number of worker threads" do + expect { subject }.to change { Gitlab::Database.config['pool'] }.from(nil).to(18) 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: max_threads - 1) - end - - it "sets it to the max number of worker threads" do - expect { subject }.to change { Gitlab::Database.config['pool'] }.by(1) - end + context "the existing pool size is smaller than the max number of worker threads" do + before do + stub_database_config(pool_size: 1) end - context "and the existing pool size is larger than the max number of worker threads" do - before do - stub_database_config(pool_size: max_threads + 1) - end + it "sets it based on the max number of worker threads" do + expect { subject }.to change { Gitlab::Database.config['pool'] }.from(1).to(18) + end + end - it "keeps the configured pool size" do - expect { subject }.not_to change { Gitlab::Database.config['pool'] } - end + context "and the existing pool size is larger than the max number of worker threads" do + before do + stub_database_config(pool_size: 100) end - context "when specifying headroom through an ENV variable" do - let(:headroom) { 10 } + it "sets it based on the max number of worker threads" do + expect { subject }.to change { Gitlab::Database.config['pool'] }.from(100).to(18) + end + end - before do - stub_database_config(pool_size: 1) - stub_env("DB_POOL_HEADROOM", headroom) - end + context "when specifying headroom through an ENV variable" do + let(:headroom) { 15 } - it "adds headroom on top of the calculated size" do - expect { subject }.to change { Gitlab::Database.config['pool'] } - .from(1) - .to(max_threads + headroom) - end + before do + stub_database_config(pool_size: 1) + stub_env("DB_POOL_HEADROOM", headroom) end - end - context "when using single-threaded runtime" do - it "does nothing" do - expect { subject }.not_to change { Gitlab::Database.config['pool'] } + it "adds headroom on top of the calculated size" do + expect { subject }.to change { Gitlab::Database.config['pool'] } + .from(1) + .to(max_threads + headroom) end end -- cgit v1.2.3