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>2022-10-20 12:40:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/initializers
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/initializers')
-rw-r--r--spec/initializers/100_patch_omniauth_oauth2_spec.rb2
-rw-r--r--spec/initializers/attr_encrypted_no_db_connection_spec.rb40
-rw-r--r--spec/initializers/attr_encrypted_thread_safe_spec.rb28
-rw-r--r--spec/initializers/diagnostic_reports_spec.rb28
-rw-r--r--spec/initializers/memory_watchdog_spec.rb76
-rw-r--r--spec/initializers/sawyer_patch_spec.rb24
-rw-r--r--spec/initializers/sidekiq_spec.rb57
7 files changed, 162 insertions, 93 deletions
diff --git a/spec/initializers/100_patch_omniauth_oauth2_spec.rb b/spec/initializers/100_patch_omniauth_oauth2_spec.rb
index 36a14816b7e..8c8e2b24484 100644
--- a/spec/initializers/100_patch_omniauth_oauth2_spec.rb
+++ b/spec/initializers/100_patch_omniauth_oauth2_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe 'OmniAuth::Strategies::OAuth2' do
it 'verifies the gem version' do
current_version = OmniAuth::OAuth2::VERSION
- expected_version = '1.7.3'
+ expected_version = '1.8.0'
expect(current_version).to eq(expected_version), <<~EOF
New version #{current_version} of the `omniauth-oauth2` gem detected!
diff --git a/spec/initializers/attr_encrypted_no_db_connection_spec.rb b/spec/initializers/attr_encrypted_no_db_connection_spec.rb
deleted file mode 100644
index 34d9e182370..00000000000
--- a/spec/initializers/attr_encrypted_no_db_connection_spec.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe 'GitLab monkey-patches to AttrEncrypted' do
- describe '#attribute_instance_methods_as_symbols_available?' do
- let(:klass) do
- Class.new(ActiveRecord::Base) do
- # We need some sort of table to work on
- self.table_name = 'projects'
-
- attr_encrypted :foo
- end
- end
-
- it 'returns false' do
- expect(ActiveRecord::Base.__send__(:attribute_instance_methods_as_symbols_available?)).to be_falsy
- end
-
- it 'does not define virtual attributes' do
- instance = klass.new
-
- aggregate_failures do
- %w[
- encrypted_foo encrypted_foo=
- encrypted_foo_iv encrypted_foo_iv=
- encrypted_foo_salt encrypted_foo_salt=
- ].each do |method_name|
- expect(instance).not_to respond_to(method_name)
- end
- end
- end
-
- it 'calls attr_changed? method with kwargs' do
- obj = klass.new
-
- expect(obj.foo_changed?).to eq(false)
- end
- end
-end
diff --git a/spec/initializers/attr_encrypted_thread_safe_spec.rb b/spec/initializers/attr_encrypted_thread_safe_spec.rb
deleted file mode 100644
index e79b7c716ec..00000000000
--- a/spec/initializers/attr_encrypted_thread_safe_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe AttrEncrypted do
- describe '#encrypted_attributes' do
- subject do
- Class.new(ActiveRecord::Base) do
- self.table_name = 'projects'
-
- attr_accessor :encrypted_foo
- attr_accessor :encrypted_foo_iv
-
- attr_encrypted :foo, key: 'This is a key that is 256 bits!!'
- end
- end
-
- it 'does not share state with other instances' do
- instance = subject.new
- instance.foo = 'bar'
-
- another_instance = subject.new
-
- expect(instance.encrypted_attributes[:foo][:operation]).to eq(:encrypting)
- expect(another_instance.encrypted_attributes[:foo][:operation]).to be_nil
- end
- end
-end
diff --git a/spec/initializers/diagnostic_reports_spec.rb b/spec/initializers/diagnostic_reports_spec.rb
index 70574194916..01b1ed9b7b5 100644
--- a/spec/initializers/diagnostic_reports_spec.rb
+++ b/spec/initializers/diagnostic_reports_spec.rb
@@ -21,25 +21,33 @@ RSpec.describe 'diagnostic reports' do
stub_env('GITLAB_DIAGNOSTIC_REPORTS_ENABLED', true)
end
- context 'when run in application context' do
+ context 'when run in Puma context' do
before do
- allow(::Gitlab::Runtime).to receive(:application?).and_return(true)
+ allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
end
- it 'modifies worker startup hooks' do
- report_daemon = instance_double(Gitlab::Memory::ReportsDaemon)
+ let(:report_daemon) { instance_double(Gitlab::Memory::ReportsDaemon) }
+ it 'modifies worker startup hooks, starts Gitlab::Memory::ReportsDaemon' do
expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_call_original
- expect(Gitlab::Memory::ReportsDaemon).to receive(:instance).and_return(report_daemon)
- expect(report_daemon).to receive(:start)
+
+ expect_next_instance_of(Gitlab::Memory::ReportsDaemon) do |daemon|
+ expect(daemon).to receive(:start).and_call_original
+
+ # make sleep no-op
+ allow(daemon).to receive(:sleep).and_return(nil)
+
+ # let alive return 3 times: true, true, false
+ allow(daemon).to receive(:alive).and_return(true, true, false)
+ end
load_initializer
end
end
- context 'when run in non-application context, such as rails console or tests' do
+ context 'when run in non-Puma context, such as rails console, tests, Sidekiq' do
before do
- allow(::Gitlab::Runtime).to receive(:application?).and_return(false)
+ allow(::Gitlab::Runtime).to receive(:puma?).and_return(false)
end
include_examples 'does not modify worker startup hooks'
@@ -48,7 +56,7 @@ RSpec.describe 'diagnostic reports' do
context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is not set' do
before do
- allow(::Gitlab::Runtime).to receive(:application?).and_return(true)
+ allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
end
include_examples 'does not modify worker startup hooks'
@@ -57,7 +65,7 @@ RSpec.describe 'diagnostic reports' do
context 'when GITLAB_DIAGNOSTIC_REPORTS_ENABLED is set to false' do
before do
stub_env('GITLAB_DIAGNOSTIC_REPORTS_ENABLED', false)
- allow(::Gitlab::Runtime).to receive(:application?).and_return(true)
+ allow(::Gitlab::Runtime).to receive(:puma?).and_return(true)
end
include_examples 'does not modify worker startup hooks'
diff --git a/spec/initializers/memory_watchdog_spec.rb b/spec/initializers/memory_watchdog_spec.rb
index 56f995b5cd3..36f96131c3d 100644
--- a/spec/initializers/memory_watchdog_spec.rb
+++ b/spec/initializers/memory_watchdog_spec.rb
@@ -4,7 +4,7 @@ require 'fast_spec_helper'
RSpec.describe 'memory watchdog' do
subject(:run_initializer) do
- load Rails.root.join('config/initializers/memory_watchdog.rb')
+ load rails_root_join('config/initializers/memory_watchdog.rb')
end
context 'when GITLAB_MEMORY_WATCHDOG_ENABLED is truthy' do
@@ -17,6 +17,7 @@ RSpec.describe 'memory watchdog' do
context 'when runtime is an application' do
let(:watchdog) { instance_double(Gitlab::Memory::Watchdog) }
let(:background_task) { instance_double(Gitlab::BackgroundTask) }
+ let(:logger) { Gitlab::AppLogger }
before do
allow(Gitlab::Runtime).to receive(:application?).and_return(true)
@@ -28,16 +29,65 @@ RSpec.describe 'memory watchdog' do
run_initializer
end
- shared_examples 'starts watchdog with handler' do |handler_class|
- it "uses the #{handler_class} and starts the watchdog" do
- expect(Gitlab::Memory::Watchdog).to receive(:new).with(
- handler: an_instance_of(handler_class),
- logger: Gitlab::AppLogger).and_return(watchdog)
- expect(Gitlab::BackgroundTask).to receive(:new).with(watchdog).and_return(background_task)
- expect(background_task).to receive(:start)
- expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_yield
+ shared_examples 'starts configured watchdog' do |handler_class|
+ let(:configuration) { Gitlab::Memory::Watchdog::Configuration.new }
+ let(:watchdog_monitors_params) do
+ {
+ Gitlab::Memory::Watchdog::Monitor::HeapFragmentation => {
+ max_heap_fragmentation: max_heap_fragmentation,
+ max_strikes: max_strikes
+ },
+ Gitlab::Memory::Watchdog::Monitor::UniqueMemoryGrowth => {
+ max_mem_growth: max_mem_growth,
+ max_strikes: max_strikes
+ }
+ }
+ end
+
+ shared_examples 'configures and starts watchdog' do
+ it "correctly configures and starts watchdog", :aggregate_failures do
+ expect(watchdog).to receive(:configure).and_yield(configuration)
+
+ watchdog_monitors_params.each do |monitor_class, params|
+ expect(configuration.monitors).to receive(:use).with(monitor_class, **params)
+ end
+
+ expect(Gitlab::Memory::Watchdog).to receive(:new).and_return(watchdog)
+ expect(Gitlab::BackgroundTask).to receive(:new).with(watchdog).and_return(background_task)
+ expect(background_task).to receive(:start)
+ expect(Gitlab::Cluster::LifecycleEvents).to receive(:on_worker_start).and_yield
+
+ run_initializer
+
+ expect(configuration.handler).to be_an_instance_of(handler_class)
+ expect(configuration.logger).to eq(logger)
+ expect(configuration.sleep_time_seconds).to eq(sleep_time_seconds)
+ end
+ end
+
+ context 'when settings are not passed through the environment' do
+ let(:max_strikes) { 5 }
+ let(:max_heap_fragmentation) { 0.5 }
+ let(:max_mem_growth) { 3.0 }
+ let(:sleep_time_seconds) { 60 }
+
+ include_examples 'configures and starts watchdog'
+ end
+
+ context 'when settings are passed through the environment' do
+ let(:max_strikes) { 6 }
+ let(:max_heap_fragmentation) { 0.4 }
+ let(:max_mem_growth) { 2.0 }
+ let(:sleep_time_seconds) { 50 }
+
+ before do
+ stub_env('GITLAB_MEMWD_MAX_STRIKES', 6)
+ stub_env('GITLAB_MEMWD_SLEEP_TIME_SEC', 50)
+ stub_env('GITLAB_MEMWD_MAX_MEM_GROWTH', 2.0)
+ stub_env('GITLAB_MEMWD_MAX_HEAP_FRAG', 0.4)
+ end
- run_initializer
+ include_examples 'configures and starts watchdog'
end
end
@@ -59,7 +109,7 @@ RSpec.describe 'memory watchdog' do
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
end
- it_behaves_like 'starts watchdog with handler', Gitlab::Memory::Watchdog::PumaHandler
+ it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::PumaHandler
end
# rubocop: enable RSpec/VerifiedDoubles
@@ -68,11 +118,11 @@ RSpec.describe 'memory watchdog' do
allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true)
end
- it_behaves_like 'starts watchdog with handler', Gitlab::Memory::Watchdog::TermProcessHandler
+ it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::TermProcessHandler
end
context 'when other runtime' do
- it_behaves_like 'starts watchdog with handler', Gitlab::Memory::Watchdog::NullHandler
+ it_behaves_like 'starts configured watchdog', Gitlab::Memory::Watchdog::NullHandler
end
end
diff --git a/spec/initializers/sawyer_patch_spec.rb b/spec/initializers/sawyer_patch_spec.rb
index dc922654d7d..b3c10e63460 100644
--- a/spec/initializers/sawyer_patch_spec.rb
+++ b/spec/initializers/sawyer_patch_spec.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'fast_spec_helper'
+require 'spec_helper'
require 'sawyer'
require_relative '../../config/initializers/sawyer_patch'
@@ -64,6 +64,28 @@ RSpec.describe 'sawyer_patch' do
expect(sawyer_resource.count_total).to eq(1)
expect(sawyer_resource.count_total?).to eq(true)
expect(sawyer_resource.count_total + 1).to eq(2)
+ sawyer_resource.count_total = 3
+ expect(sawyer_resource.count_total).to eq(3)
expect(sawyer_resource.user.name).to eq('User name')
end
+
+ it 'logs when a sawyer resource dynamic method is called' do
+ sawyer_resource = Sawyer::Resource.new(
+ Sawyer::Agent.new(''),
+ {
+ count_total: 1,
+ user: { name: 'User name' }
+ }
+ )
+ expected_attributes = []
+ allow(Gitlab::Import::Logger).to receive(:warn) do |params|
+ expected_attributes.push(params[:attribute])
+ end
+
+ sawyer_resource.count_total
+ sawyer_resource.user
+ sawyer_resource.user.name
+
+ expect(expected_attributes).to match_array(%i[count_total user user name])
+ end
end
diff --git a/spec/initializers/sidekiq_spec.rb b/spec/initializers/sidekiq_spec.rb
index e34f59c3427..063dddd8c46 100644
--- a/spec/initializers/sidekiq_spec.rb
+++ b/spec/initializers/sidekiq_spec.rb
@@ -42,4 +42,61 @@ RSpec.describe 'sidekiq' do
it { is_expected.to be_falsey }
end
end
+
+ describe 'load_cron_jobs!' do
+ subject { load_cron_jobs! }
+
+ let(:cron_for_service_ping) { '4 7 * * 4' }
+
+ let(:cron_jobs_settings) do
+ {
+ 'gitlab_service_ping_worker' => {
+ 'cron' => nil,
+ 'job_class' => 'GitlabServicePingWorker'
+ },
+ 'import_export_project_cleanup_worker' => {
+ 'cron' => '0 * * * *',
+ 'job_class' => 'ImportExportProjectCleanupWorker'
+ },
+ "invalid_worker" => {
+ 'cron' => '0 * * * *'
+ }
+ }
+ end
+
+ let(:cron_jobs_hash) do
+ {
+ 'gitlab_service_ping_worker' => {
+ 'cron' => cron_for_service_ping,
+ 'class' => 'GitlabServicePingWorker'
+ },
+ 'import_export_project_cleanup_worker' => {
+ 'cron' => '0 * * * *',
+ 'class' => 'ImportExportProjectCleanupWorker'
+ }
+ }
+ end
+
+ around do |example|
+ original_settings = Gitlab.config['cron_jobs']
+ Gitlab.config['cron_jobs'] = cron_jobs_settings
+
+ example.run
+
+ Gitlab.config['cron_jobs'] = original_settings
+ end
+
+ it 'loads the cron jobs into sidekiq-cron' do
+ allow(Settings).to receive(:cron_for_service_ping).and_return(cron_for_service_ping)
+
+ expect(Sidekiq::Cron::Job).to receive(:load_from_hash!).with(cron_jobs_hash)
+
+ if Gitlab.ee?
+ expect(Gitlab::Mirror).to receive(:configure_cron_job!)
+ expect(Gitlab::Geo).to receive(:configure_cron_jobs!)
+ end
+
+ subject
+ end
+ end
end