diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/initializers | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/initializers')
-rw-r--r-- | spec/initializers/00_deprecations_spec.rb | 172 | ||||
-rw-r--r-- | spec/initializers/0_log_deprecations_spec.rb | 138 | ||||
-rw-r--r-- | spec/initializers/0_postgresql_types_spec.rb | 2 | ||||
-rw-r--r-- | spec/initializers/check_forced_decomposition_spec.rb | 124 | ||||
-rw-r--r-- | spec/initializers/countries_spec.rb | 15 | ||||
-rw-r--r-- | spec/initializers/database_config_spec.rb | 2 | ||||
-rw-r--r-- | spec/initializers/google_api_client_spec.rb | 3 | ||||
-rw-r--r-- | spec/initializers/load_balancing_spec.rb | 2 | ||||
-rw-r--r-- | spec/initializers/memory_watchdog_spec.rb | 8 |
9 files changed, 305 insertions, 161 deletions
diff --git a/spec/initializers/00_deprecations_spec.rb b/spec/initializers/00_deprecations_spec.rb index e52e64415af..a12d079082b 100644 --- a/spec/initializers/00_deprecations_spec.rb +++ b/spec/initializers/00_deprecations_spec.rb @@ -2,19 +2,165 @@ require 'spec_helper' -RSpec.describe '00_deprecations' do - where(:warning) do - [ - "ActiveModel::Errors#keys is deprecated and will be removed in Rails 6.2", - "Rendering actions with '.' in the name is deprecated:", - "default_hash is deprecated and will be removed from Rails 6.2" - ] - end - - with_them do - specify do - expect { ActiveSupport::Deprecation.warn(warning) } - .to raise_error(ActiveSupport::DeprecationException) +RSpec.describe '00_deprecations', feature_category: :shared do + def setup_other_deprecations + Warning.process(__FILE__) { :default } + end + + def load_initializer + load Rails.root.join('config/initializers/00_deprecations.rb') + end + + let(:rails_env) { nil } + let(:gitlab_log_deprecations) { nil } + + before do + stub_rails_env(rails_env) if rails_env + stub_env('GITLAB_LOG_DEPRECATIONS', gitlab_log_deprecations) + + setup_other_deprecations + + ActiveSupport::Deprecation.disallowed_warnings = nil + ActiveSupport::Notifications.unsubscribe('deprecation.rails') + + load_initializer + end + + around do |example| + Warning.clear(&example) + end + + shared_examples 'logs to Gitlab::DeprecationJsonLogger' do |message, source| + it 'logs them to Gitlab::DeprecationJsonLogger' do + expect(Gitlab::DeprecationJsonLogger).to receive(:info).with( + message: match(/^#{message}/), + source: source + ) + + subject + end + end + + shared_examples 'does not log to Gitlab::DeprecationJsonLogger' do + it 'does not log them to Gitlab::DeprecationJsonLogger' do + expect(Gitlab::DeprecationJsonLogger).not_to receive(:info) + + subject + end + end + + shared_examples 'logs to stderr' do |message| + it 'logs them to stderr' do + expect { subject }.to output(match(/^#{message}/)).to_stderr + end + end + + shared_examples 'does not log to stderr' do + it 'does not log them to stderr' do + expect { subject }.not_to output.to_stderr + end + end + + describe 'Ruby deprecations' do + context 'when catching deprecations through Kernel#warn' do + subject { warn('ABC gem is deprecated and will be removed') } + + include_examples 'logs to Gitlab::DeprecationJsonLogger', 'ABC gem is deprecated and will be removed', 'ruby' + include_examples 'logs to stderr', 'ABC gem is deprecated and will be removed' + + context 'when in production environment' do + let(:rails_env) { 'production' } + + include_examples 'does not log to Gitlab::DeprecationJsonLogger' + include_examples 'logs to stderr', 'ABC gem is deprecated and will be removed' + + context 'when GITLAB_LOG_DEPRECATIONS is set' do + let(:gitlab_log_deprecations) { '1' } + + include_examples 'logs to Gitlab::DeprecationJsonLogger', 'ABC gem is deprecated and will be removed', 'ruby' + include_examples 'logs to stderr', 'ABC gem is deprecated and will be removed' + end + end + end + + context 'when other messages from Kernel#warn' do + subject { warn('Sure is hot today') } + + include_examples 'does not log to Gitlab::DeprecationJsonLogger' + include_examples 'logs to stderr', 'Sure is hot today' + end + end + + describe 'Rails deprecations' do + context 'when catching deprecation warnings' do + subject { ActiveSupport::Deprecation.warn('ABC will be removed') } + + include_examples 'logs to Gitlab::DeprecationJsonLogger', 'DEPRECATION WARNING: ABC will be removed', 'rails' + include_examples 'logs to stderr', 'DEPRECATION WARNING: ABC will be removed' + + context 'when in production environment' do + let(:rails_env) { 'production' } + + include_examples 'does not log to Gitlab::DeprecationJsonLogger' + include_examples 'does not log to stderr' + + context 'when GITLAB_LOG_DEPRECATIONS is set' do + let(:gitlab_log_deprecations) { '1' } + + include_examples 'logs to Gitlab::DeprecationJsonLogger', 'DEPRECATION WARNING: ABC will be removed', 'rails' + include_examples 'does not log to stderr' + end + end + end + + context 'when catching disallowed warnings' do + before do + ActiveSupport::Deprecation.disallowed_warnings << /disallowed warning 1/ + end + + subject { ActiveSupport::Deprecation.warn('This is disallowed warning 1.') } + + it 'raises ActiveSupport::DeprecationException' do + expect { subject }.to raise_error(ActiveSupport::DeprecationException) + end + + context 'when in production environment' do + let(:rails_env) { 'production' } + + it 'does not raise ActiveSupport::DeprecationException' do + expect { subject }.not_to raise_error + end + + context 'when GITLAB_LOG_DEPRECATIONS is set' do + let(:gitlab_log_deprecations) { '1' } + + it 'does not raise ActiveSupport::DeprecationException' do + expect { subject }.not_to raise_error + end + end + end + end + + describe 'configuring ActiveSupport::Deprecation.disallowed_warnings' do + it 'sets disallowed warnings' do + expect(ActiveSupport::Deprecation.disallowed_warnings).not_to be_empty + end + + context 'when in production environment' do + let(:rails_env) { 'production' } + + it 'does not set disallowed warnings' do + expect(ActiveSupport::Deprecation.disallowed_warnings).to be_empty + end + + context 'when GITLAB_LOG_DEPRECATIONS is set' do + let(:gitlab_log_deprecations) { '1' } + + it 'does not set disallowed warnings' do + expect(ActiveSupport::Deprecation.disallowed_warnings).to be_empty + end + end + end end end end diff --git a/spec/initializers/0_log_deprecations_spec.rb b/spec/initializers/0_log_deprecations_spec.rb deleted file mode 100644 index d34be32f7d0..00000000000 --- a/spec/initializers/0_log_deprecations_spec.rb +++ /dev/null @@ -1,138 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe '0_log_deprecations' do - def setup_other_deprecations - Warning.process(__FILE__) { :default } - end - - def load_initializer - load Rails.root.join('config/initializers/0_log_deprecations.rb') - end - - def with_deprecation_behavior - behavior = ActiveSupport::Deprecation.behavior - ActiveSupport::Deprecation.behavior = deprecation_behavior - yield - ensure - ActiveSupport::Deprecation.behavior = behavior - end - - let(:deprecation_behavior) { :stderr } - let(:env_var) { '1' } - - before do - stub_env('GITLAB_LOG_DEPRECATIONS', env_var) - setup_other_deprecations - load_initializer - end - - after do - ActiveSupport::Notifications.unsubscribe('deprecation.rails') - end - - around do |example| - with_deprecation_behavior do - # reset state changed by initializer - Warning.clear(&example) - end - end - - describe 'Ruby deprecations' do - shared_examples 'deprecation logger' do - it 'logs them to deprecation logger once and to stderr' do - expect(Gitlab::DeprecationJsonLogger).to receive(:info).with( - message: 'ABC gem is deprecated', - source: 'ruby' - ) - - expect { subject }.to output.to_stderr - end - end - - context 'when catching deprecations through Kernel#warn' do - subject { warn('ABC gem is deprecated') } - - include_examples 'deprecation logger' - - context 'with non-notify deprecation behavior' do - let(:deprecation_behavior) { :silence } - - include_examples 'deprecation logger' - end - - context 'with notify deprecation behavior' do - let(:deprecation_behavior) { :notify } - - include_examples 'deprecation logger' - end - end - - describe 'other messages from Kernel#warn' do - it 'does not log them to deprecation logger' do - expect(Gitlab::DeprecationJsonLogger).not_to receive(:info) - - expect { warn('Sure is hot today') }.to output.to_stderr - end - end - - context 'when disabled via environment' do - let(:env_var) { '0' } - - it 'does not log them to deprecation logger' do - expect(Gitlab::DeprecationJsonLogger).not_to receive(:info) - - expect { warn('ABC gem is deprecated') }.to output.to_stderr - end - end - end - - describe 'Rails deprecations' do - subject { ActiveSupport::Deprecation.warn('ABC will be removed') } - - shared_examples 'deprecation logger' do - it 'logs them to deprecation logger once' do - expect(Gitlab::DeprecationJsonLogger).to receive(:info).with( - message: match(/^DEPRECATION WARNING: ABC will be removed/), - source: 'rails' - ) - - subject - end - end - - context 'with non-notify deprecation behavior' do - let(:deprecation_behavior) { :silence } - - include_examples 'deprecation logger' - end - - context 'with notify deprecation behavior' do - let(:deprecation_behavior) { :notify } - - include_examples 'deprecation logger' - end - - context 'when deprecations were silenced' do - around do |example| - silenced = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = true - example.run - ActiveSupport::Deprecation.silenced = silenced - end - - include_examples 'deprecation logger' - end - - context 'when disabled via environment' do - let(:env_var) { '0' } - - it 'does not log them to deprecation logger' do - expect(Gitlab::DeprecationJsonLogger).not_to receive(:info) - - expect { ActiveSupport::Deprecation.warn('ABC will be removed') }.to output.to_stderr - end - end - end -end diff --git a/spec/initializers/0_postgresql_types_spec.rb b/spec/initializers/0_postgresql_types_spec.rb index 76b243033d0..99f9b76a34e 100644 --- a/spec/initializers/0_postgresql_types_spec.rb +++ b/spec/initializers/0_postgresql_types_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'PostgreSQL registered types' do - subject(:types) { ApplicationRecord.connection.send(:type_map).keys } + subject(:types) { ApplicationRecord.connection.reload_type_map.keys } # These can be obtained via SELECT oid, typname from pg_type it 'includes custom and standard OIDs' do diff --git a/spec/initializers/check_forced_decomposition_spec.rb b/spec/initializers/check_forced_decomposition_spec.rb new file mode 100644 index 00000000000..a216f078932 --- /dev/null +++ b/spec/initializers/check_forced_decomposition_spec.rb @@ -0,0 +1,124 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'check_forced_decomposition initializer', feature_category: :pods do + subject(:check_forced_decomposition) do + load Rails.root.join('config/initializers/check_forced_decomposition.rb') + end + + before do + stub_env('GITLAB_ALLOW_SEPARATE_CI_DATABASE', nil) + end + + context 'for production env' do + before do + allow(Gitlab).to receive(:dev_or_test_env?).and_return(false) + end + + context 'for single database' do + before do + skip_if_multiple_databases_are_setup + end + + it { expect { check_forced_decomposition }.not_to raise_error } + end + + context 'for multiple database' do + before do + skip_if_multiple_databases_not_setup + end + + let(:main_database_config) do + Rails.application.config.load_database_yaml + .dig('test', 'main') + .slice('adapter', 'encoding', 'database', 'username', 'password', 'host') + .symbolize_keys + end + + let(:additional_database_config) do + # Use built-in postgres database + main_database_config.merge(database: 'postgres') + end + + around do |example| + with_reestablished_active_record_base(reconnect: true) do + with_db_configs(test: test_config) do + example.run + end + end + end + + context 'when ci and main share the same database' do + let(:test_config) do + { + main: main_database_config, + ci: additional_database_config.merge(database: main_database_config[:database]) + } + end + + it { expect { check_forced_decomposition }.not_to raise_error } + + context 'when host is not present' do + let(:test_config) do + { + main: main_database_config.except(:host), + ci: additional_database_config.merge(database: main_database_config[:database]).except(:host) + } + end + + it { expect { check_forced_decomposition }.not_to raise_error } + end + end + + context 'when ci and main share the same database but different host' do + let(:test_config) do + { + main: main_database_config, + ci: additional_database_config.merge( + database: main_database_config[:database], + host: 'otherhost.localhost' + ) + } + end + + it { expect { check_forced_decomposition }.to raise_error(/Separate CI database is not ready/) } + end + + context 'when ci and main are different databases' do + let(:test_config) do + { + main: main_database_config, + ci: additional_database_config + } + end + + it { expect { check_forced_decomposition }.to raise_error(/Separate CI database is not ready/) } + + context 'for GitLab.com' do + before do + allow(::Gitlab).to receive(:com?).and_return(true) + end + + it { expect { check_forced_decomposition }.not_to raise_error } + end + + context 'when env var GITLAB_ALLOW_SEPARATE_CI_DATABASE is true' do + before do + stub_env('GITLAB_ALLOW_SEPARATE_CI_DATABASE', 'true') + end + + it { expect { check_forced_decomposition }.not_to raise_error } + end + + context 'when env var GITLAB_ALLOW_SEPARATE_CI_DATABASE is false' do + before do + stub_env('GITLAB_ALLOW_SEPARATE_CI_DATABASE', 'false') + end + + it { expect { check_forced_decomposition }.to raise_error(/Separate CI database is not ready/) } + end + end + end + end +end diff --git a/spec/initializers/countries_spec.rb b/spec/initializers/countries_spec.rb new file mode 100644 index 00000000000..2b968e41322 --- /dev/null +++ b/spec/initializers/countries_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +RSpec.describe 'countries', feature_category: :onboarding do + it 'configures locals to EN' do + expect(ISO3166.configuration.locales).to eq([:en]) + end + + it 'initialises Ukraine with custom country name' do + expect(ISO3166::Country['UA'].data["name"]).to be('Ukraine (except the Crimea, Donetsk, and Luhansk regions)') + end + + it 'initialises Taiwan with custom country name' do + expect(ISO3166::Country['TW'].data["name"]).to be('Taiwan') + end +end diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index bbb5e7b1923..f3f1f326dad 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -29,7 +29,7 @@ RSpec.describe 'Database config initializer', :reestablished_active_record_base context 'when ci database connection' do before do - skip_if_multiple_databases_not_setup + skip_if_multiple_databases_not_setup(:ci) end let(:database_base_model) { Gitlab::Database.database_base_models[:ci] } diff --git a/spec/initializers/google_api_client_spec.rb b/spec/initializers/google_api_client_spec.rb index 0ed82d7debe..b3c4ac5e23b 100644 --- a/spec/initializers/google_api_client_spec.rb +++ b/spec/initializers/google_api_client_spec.rb @@ -26,8 +26,9 @@ RSpec.describe Google::Apis::Core::HttpCommand do # rubocop:disable RSpec/FilePa it 'retries with max elapsed_time and retries' do expect(Retriable).to receive(:retriable).with( tries: Google::Apis::RequestOptions.default.retries + 1, - max_elapsed_time: 3600, + max_elapsed_time: 900, base_interval: 1, + max_interval: 60, multiplier: 2, on: described_class::RETRIABLE_ERRORS).and_call_original allow(Retriable).to receive(:retriable).and_call_original diff --git a/spec/initializers/load_balancing_spec.rb b/spec/initializers/load_balancing_spec.rb index d9162acd2cd..66aaa52eef2 100644 --- a/spec/initializers/load_balancing_spec.rb +++ b/spec/initializers/load_balancing_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'load_balancing', :delete, :reestablished_active_record_base do +RSpec.describe 'load_balancing', :delete, :reestablished_active_record_base, feature_category: :pods do subject(:initialize_load_balancer) do load Rails.root.join('config/initializers/load_balancing.rb') end diff --git a/spec/initializers/memory_watchdog_spec.rb b/spec/initializers/memory_watchdog_spec.rb index 92834c889c2..ef24da0071b 100644 --- a/spec/initializers/memory_watchdog_spec.rb +++ b/spec/initializers/memory_watchdog_spec.rb @@ -2,7 +2,7 @@ require 'fast_spec_helper' -RSpec.describe 'memory watchdog' do +RSpec.describe 'memory watchdog', feature_category: :application_performance do shared_examples 'starts configured watchdog' do |configure_monitor_method| shared_examples 'configures and starts watchdog' do it "correctly configures and starts watchdog", :aggregate_failures do @@ -104,11 +104,7 @@ RSpec.describe 'memory watchdog' do allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) end - it 'does not register life-cycle hook' do - expect(Gitlab::Cluster::LifecycleEvents).not_to receive(:on_worker_start) - - run_initializer - end + it_behaves_like 'starts configured watchdog', :configure_for_sidekiq end end end |