Commit dcf22631 authored by Stan Hu's avatar Stan Hu

Merge branch '205640-dont-ignore-database-errors' into 'master'

Do not ignore database connection errors

See merge request gitlab-org/gitlab!29400
parents 2f1250cd b7de942a
...@@ -43,7 +43,7 @@ module Gitlab ...@@ -43,7 +43,7 @@ module Gitlab
end end
def uncached_application_settings def uncached_application_settings
return fake_application_settings unless connect_to_db? return fake_application_settings if Gitlab::Runtime.rake? && !connect_to_db?
current_settings = ::ApplicationSetting.current current_settings = ::ApplicationSetting.current
# If there are pending migrations, it's possible there are columns that # If there are pending migrations, it's possible there are columns that
......
...@@ -49,20 +49,16 @@ describe Gitlab::CurrentSettings do ...@@ -49,20 +49,16 @@ describe Gitlab::CurrentSettings do
end end
end end
context 'with DB unavailable' do context 'in a Rake task with DB unavailable' do
context 'and settings in cache' do before do
include_context 'with settings in cache' allow(Gitlab::Runtime).to receive(:rake?).and_return(true)
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(false)` causes issues
it 'fetches the settings from cache without issuing any query' do # during the initialization phase of the test suite, so instead let's mock the internals of it
expect(ActiveRecord::QueryRecorder.new { described_class.current_application_settings }.count).to eq(0) allow(ActiveRecord::Base.connection).to receive(:active?).and_return(false)
end
end end
context 'and no settings in cache' do context 'and no settings in cache' do
before do before do
# For some reason, `allow(described_class).to receive(:connect_to_db?).and_return(false)` causes issues
# during the initialization phase of the test suite, so instead let's mock the internals of it
allow(ActiveRecord::Base.connection).to receive(:active?).and_return(false)
expect(ApplicationSetting).not_to receive(:current) expect(ApplicationSetting).not_to receive(:current)
end end
...@@ -185,17 +181,6 @@ describe Gitlab::CurrentSettings do ...@@ -185,17 +181,6 @@ describe Gitlab::CurrentSettings do
expect(described_class.current_application_settings).to eq(:current_settings) expect(described_class.current_application_settings).to eq(:current_settings)
end end
end end
context 'when the application_settings table does not exist' do
it 'returns a FakeApplicationSettings object' do
expect(Gitlab::Database)
.to receive(:cached_table_exists?)
.with('application_settings')
.and_return(false)
expect(described_class.current_application_settings).to be_a(Gitlab::FakeApplicationSettings)
end
end
end end
end end
end end
......
...@@ -80,6 +80,9 @@ module MigrationsHelpers ...@@ -80,6 +80,9 @@ module MigrationsHelpers
allow(ActiveRecord::Base.connection) allow(ActiveRecord::Base.connection)
.to receive(:active?) .to receive(:active?)
.and_return(false) .and_return(false)
allow(Gitlab::Runtime)
.to receive(:rake?)
.and_return(true)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end end
......
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