summaryrefslogtreecommitdiff
path: root/spec/initializers/database_config_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/initializers/database_config_spec.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/initializers/database_config_spec.rb')
-rw-r--r--spec/initializers/database_config_spec.rb72
1 files changed, 30 insertions, 42 deletions
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