Commit cc732f12 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'cat-validateconfig-allow-connectionnotestablished' into 'master'

Allow ConnectionNotEstablished for DB rake tasks using validate_config

See merge request gitlab-org/gitlab!84167
parents 305af3cd f1ab6546
...@@ -20,7 +20,7 @@ namespace :gitlab do ...@@ -20,7 +20,7 @@ namespace :gitlab do
begin begin
ActiveRecord::Base.establish_connection(db_config) # rubocop: disable Database/EstablishConnection ActiveRecord::Base.establish_connection(db_config) # rubocop: disable Database/EstablishConnection
ActiveRecord::Base.connection.select_one("SELECT system_identifier, current_database() FROM pg_control_system()") ActiveRecord::Base.connection.select_one("SELECT system_identifier, current_database() FROM pg_control_system()")
rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished, PG::ConnectionBad
end end
{ {
......
...@@ -53,6 +53,18 @@ RSpec.describe 'gitlab:db:validate_config', :silence_stdout do ...@@ -53,6 +53,18 @@ RSpec.describe 'gitlab:db:validate_config', :silence_stdout do
expect { run_rake_task('gitlab:db:validate_config') }.not_to output(/Database config validation failure/).to_stderr expect { run_rake_task('gitlab:db:validate_config') }.not_to output(/Database config validation failure/).to_stderr
expect { run_rake_task('gitlab:db:validate_config') }.not_to raise_error expect { run_rake_task('gitlab:db:validate_config') }.not_to raise_error
end end
context 'when finding the initializer fails' do
where(:raised_error) { [ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished, PG::ConnectionBad] }
with_them do
it "does not raise an error for #{params[:raised_error]}" do
allow(ActiveRecord::Base.connection).to receive(:select_one).and_raise(raised_error) # rubocop: disable Database/MultipleDatabases
expect { run_rake_task('gitlab:db:validate_config') }.not_to output(/Database config validation failure/).to_stderr
expect { run_rake_task('gitlab:db:validate_config') }.not_to raise_error
end
end
end
end end
shared_examples 'raises an error' do |match| shared_examples 'raises an error' do |match|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment