Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 21:25:58 +0300
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /spec/initializers
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/initializers')
-rw-r--r--spec/initializers/database_config_spec.rb26
-rw-r--r--spec/initializers/global_id_spec.rb35
-rw-r--r--spec/initializers/lograge_spec.rb56
-rw-r--r--spec/initializers/mailer_retries_spec.rb25
4 files changed, 134 insertions, 8 deletions
diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb
index ccd69de0b3a..f1b353d4012 100644
--- a/spec/initializers/database_config_spec.rb
+++ b/spec/initializers/database_config_spec.rb
@@ -7,8 +7,15 @@ RSpec.describe 'Database config initializer' do
load Rails.root.join('config/initializers/database_config.rb')
end
+ around do |example|
+ original_config = ActiveRecord::Base.connection_db_config
+
+ example.run
+
+ ActiveRecord::Base.establish_connection(original_config)
+ end
+
before do
- allow(ActiveRecord::Base).to receive(:establish_connection)
allow(Gitlab::Runtime).to receive(:max_threads).and_return(max_threads)
end
@@ -21,6 +28,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(nil).to(18)
+
+ expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end
end
@@ -31,6 +40,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(1).to(18)
+
+ expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end
end
@@ -41,6 +52,8 @@ RSpec.describe 'Database config initializer' do
it "sets it based on the max number of worker threads" do
expect { subject }.to change { Gitlab::Database.config['pool'] }.from(100).to(18)
+
+ expect(ActiveRecord::Base.connection_db_config.pool).to eq(18)
end
end
@@ -56,15 +69,16 @@ RSpec.describe 'Database config initializer' do
expect { subject }.to change { Gitlab::Database.config['pool'] }
.from(1)
.to(max_threads + headroom)
+
+ expect(ActiveRecord::Base.connection_db_config.pool).to eq(max_threads + headroom)
end
end
def stub_database_config(pool_size:)
- config = {
- 'adapter' => 'postgresql',
- 'host' => 'db.host.com',
- 'pool' => pool_size
- }.compact
+ original_config = Gitlab::Database.config
+
+ config = original_config.dup
+ config['pool'] = pool_size
allow(Gitlab::Database).to receive(:config).and_return(config)
end
diff --git a/spec/initializers/global_id_spec.rb b/spec/initializers/global_id_spec.rb
new file mode 100644
index 00000000000..63bfa32d74f
--- /dev/null
+++ b/spec/initializers/global_id_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'global_id' do
+ it 'prepends `Gitlab::Patch::GlobalID`' do
+ expect(GlobalID.ancestors).to include(Gitlab::Patch::GlobalID)
+ end
+
+ it 'patches GlobalID to find aliased models when a deprecation exists' do
+ allow(Gitlab::GlobalId::Deprecations).to receive(:deprecation_for).and_call_original
+ allow(Gitlab::GlobalId::Deprecations).to receive(:deprecation_for).with('Issue').and_return(double(new_model_name: 'Project'))
+ project = create(:project)
+ gid_string = Gitlab::GlobalId.build(model_name: Issue.name, id: project.id).to_s
+
+ expect(GlobalID.new(gid_string)).to have_attributes(
+ to_s: gid_string,
+ model_name: 'Project',
+ model_class: Project,
+ find: project
+ )
+ end
+
+ it 'works as normal when no deprecation exists' do
+ issue = create(:issue)
+ gid_string = Gitlab::GlobalId.build(model_name: Issue.name, id: issue.id).to_s
+
+ expect(GlobalID.new(gid_string)).to have_attributes(
+ to_s: gid_string,
+ model_name: 'Issue',
+ model_class: Issue,
+ find: issue
+ )
+ end
+end
diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb
index 421f6373eff..651b0c8a9b8 100644
--- a/spec/initializers/lograge_spec.rb
+++ b/spec/initializers/lograge_spec.rb
@@ -120,6 +120,7 @@ RSpec.describe 'lograge', type: :request do
context 'with a log subscriber' do
include_context 'parsed logs'
+ include_context 'clear DB Load Balancing configuration'
let(:subscriber) { Lograge::LogSubscribers::ActionController.new }
@@ -195,9 +196,25 @@ RSpec.describe 'lograge', type: :request do
end
context 'with db payload' do
+ let(:db_load_balancing_logging_keys) do
+ %w[
+ db_primary_wal_count
+ db_replica_wal_count
+ db_replica_count
+ db_replica_cached_count
+ db_primary_count
+ db_primary_cached_count
+ db_primary_duration_s
+ db_replica_duration_s
+ ]
+ end
+
+ before do
+ ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
+ end
+
context 'when RequestStore is enabled', :request_store do
it 'includes db counters' do
- ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
subscriber.process_action(event)
expect(log_data).to include("db_count" => a_value >= 1, "db_write_count" => 0, "db_cached_count" => 0)
@@ -206,12 +223,47 @@ RSpec.describe 'lograge', type: :request do
context 'when RequestStore is disabled' do
it 'does not include db counters' do
- ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
subscriber.process_action(event)
expect(log_data).not_to include("db_count", "db_write_count", "db_cached_count")
end
end
+
+ context 'when load balancing is enabled' do
+ before do
+ allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
+ end
+
+ context 'with db payload' do
+ context 'when RequestStore is enabled', :request_store do
+ it 'includes db counters for load balancing' do
+ subscriber.process_action(event)
+
+ expect(log_data).to include(*db_load_balancing_logging_keys)
+ end
+ end
+
+ context 'when RequestStore is disabled' do
+ it 'does not include db counters for load balancing' do
+ subscriber.process_action(event)
+
+ expect(log_data).not_to include(*db_load_balancing_logging_keys)
+ end
+ end
+ end
+ end
+
+ context 'when load balancing is disabled' do
+ before do
+ allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(false)
+ end
+
+ it 'does not include db counters for load balancing' do
+ subscriber.process_action(event)
+
+ expect(log_data).not_to include(*db_load_balancing_logging_keys)
+ end
+ end
end
end
end
diff --git a/spec/initializers/mailer_retries_spec.rb b/spec/initializers/mailer_retries_spec.rb
new file mode 100644
index 00000000000..c1e56784ad9
--- /dev/null
+++ b/spec/initializers/mailer_retries_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Mailer retries' do
+ # We need to ensure that this runs through Sidekiq to take
+ # advantage of the middleware. There is a Rails bug that means we
+ # have to do some extra steps to make this happen:
+ # https://github.com/rails/rails/issues/37270#issuecomment-553927324
+ around do |example|
+ descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
+ descendants.each(&:disable_test_adapter)
+ ActiveJob::Base.queue_adapter = :sidekiq
+
+ example.run
+
+ descendants.each { |a| a.queue_adapter = :test }
+ end
+
+ it 'sets retries for mailers to 3', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332645' do
+ DeviseMailer.user_admin_approval(create(:user)).deliver_later
+
+ expect(Sidekiq::Queues['mailers'].first).to include('retry' => 3)
+ end
+end